There are many ways to accomplish what you want to do - silent monitoring with headphones and recording of your guitar on computer. The Line 6 Pod systems as mentioned by manejar are great.
Another option that should work would be a simple audio interface such as this one
PreSonus AudioBox USB which has two line inputs for guitar or mic, a headphone jack and connects to computer via USB and also has monitor out jacks. It comes bundled with Studio One® Artist DAW software for Mac and Windows. But I have not personally used this one. I had a similar type interface from M-Audio and it worked fine.
What I use now that I do know will work, but may be much more than you need is a Boss BR-800 Multi Track Recorder like this Boss BR-800.
This unit will allow you to record your guitar on any one of 8 channels, while listening to it with headphones (no amp required) and also while listening to the song you are playing along with (while listening to everything through the units headphone jack). It has line in recording capability so you can record something playing on your computer or i-pod by plugging into the line in jack on the back.
You can plug in acoustic/electric or hi-Z electric guitar or bass or microphones with SLR input (either dynamic or condenser). It also has guitar effects that are almost infinitely adjustable and you can create your own pre-set effects. It has multiple amp emulations as well.
You can record your backing music on one track your guitar on another, then play those two channels back while playing a second guitar part (perhaps with overdrive) over top of the first guitar part and build more parts if you like. If you don't have a bass guitar but want to add a bass line to your recording, you can use the "guitar to bass simulator" that will make your guitar sound like any of several different type bass guitars.
If you mess up in a certain section when making your recording, rather than start all over, you can just "punch-in" over the mistake (re-record just the one section).
After you finish your recording, you can add other effects during the mastering phase and adjust the relative volume of the various tracks during mastering. So if you record yourself playing on one track and the backing music from YouTube on another track, you can adjust the volume on each track to get the balance between the two just right. You can also adjust the gain of each channel during recording.
It also has built in drum samples (it's almost like a drum machine) that you can play to and record if you choose. It also has a cool feature where you can record something off YouTube for example and then play it back at half speed and you can loop a certain section if you want to learn to play a certain riff.
It will plug into your computer via USB, it comes with free DAW recording software, and you can use it as a control surface for most DAW software programs. Also really handy, is everything is recorded onto a standard SD card and I just pop that into my computer to transfer the files.
Another really handy feature is that you can plug it in - or run it on AA batteries so you can even take it camping or to the beach or out on a boat and record, and playback through headphones or monitor. It even has built in stereo mics you can use for recording a quick acoustic performance if you select the built in mics.
And like I said, you don't have to use your amp, although you could plug your amp into one of the inputs from your headphone jack on your amplifier and plug your headphones into the headphone jack on the Boss Recorder.
I am sure there will be other options posted as well. I personally would make a purchase of this nature from a retailer with a generous and no-hassle return policy and verify the return policy for the particular equipment you want to buy. Then if it does not do what you want, the way you want it to, you can return it for a refund or exchange it for something different to try.
DISCLAIMER: No I do not work for Boss - I just love my BR-800 (can you tell?).