What you're talking about is called Cleaning
This video covers the process in detail.
But in short:
- Attach your self to the top anchor with a spare clip draw (or two), or better yet a sling attached to your harness using a larks foot and a locking biner.
- Inform your belayer that you're safe (but not off belay)
- Tie a figure of eight on the bight in the rope
- Attach the rope to yourself using this knot (prevents you from dropping it), use a locking biner for this
- Untie your attachment figure of eight
- Feed rope through the rings at the top (should be two)
- re-tie the end of the rope to your harness
- Once you're happy you're attached correctly and safe shout on belay to your belayer, they should take any slack
- remove and untie retaining knot on rope
- weight the rope to confirm it's attached safe (communicate this too your belayer)
- remove quick draw(s) attaching you to the anchors
- Lower off
- Remove quick draws as you descend
- Once you're on the ground untie and pull rope out of belay loops
Leaving a top rope on
If you want to top rope on this climb afterwards the stages above are identical. The only difference being that you shouldn't attach directly to the rap rings (this causes friction that wears them out).
Some people will attach to the rap rings using two quick draws, I'm not a fan of this TBH, quick draws aren't screwgates and can pop open if the load is applied in the correct manner.
I would always attach top ropes with two opposites screw gates (you can use some slings if you want a bit of slack at the top).
It's very important that the two screwgates undo in opposite directions, this stops them unscrewing as the rope runs through them. Put one on, turn the next one upside down (relative two the first) and then put the second on, you should have to unscrew each screw gate in the opposing direction to it's partner.
Check the rap rings carefully before using. These things are not bomb proof, they can and do fail. If they are loose or look corroded or heavily worn, don't use them (or provide a bomb proof backup).
Bad rap rings:
There has been a recent problem in North Wales where expansion bolts in slate have bbeen proven to be unsafe and all of them (hundreds) are being replaced by the BMC.
Retreating is a bit more complex. To retreat you need to leave some gear behind. Best is some cheap (but strong) locking steel biners. You basically do the same as above (but rather than looping the rope through the anchor, you attach the biners to the anchor and link through these (~your rope won't fit through a typical sport anchor)
If you're not too high the above is fine. If you're high (or want to be safe) this introduces a single point of failure to your system (if that anchor fails you're dead).
A good method to avoid this is to loop the rope though the top anchor (using your biners) and the one below it. This way you have a back up to the first failing.
- So loop yourself though the top most anchor, as above.
- Lower off a little to the second anchor
- Attach the rope (the end going to your belayer) to this anchor using your second carabiner (do this before you remove the quick draw)
- Remove the quick draw and clean as usual
Here's an article that seems to cover it all