I'll start with the simplest solution first, the iPhone. You may already know this, but If you check the option in iTunes to convert higher quality music and select 256 kbps, it's easy to automatically sync to your iPhone while keeping your lossless files intact. This is worth doing anyway if you have the space, as you then have your music wherever you go. 256 kbps sounds pretty good through headphones. Although the more you spend on headphones, the more likely you will want lossless because quality headphone listening can be very revealing of compression artefacts.
Moving on to ATV.
Airplay itself is a lossless transmission scheme. If you send a lossless file, it is sent as is, and arrives at ATV as lossless. If you send a lower bitrate file, say 256 kbps, it gets unconverted to lossless before transmission. That does not improve the quality magically back to that of a lossless file, it just means that it doesn't get any worse if that makes sense.
There is a slight caveat that the only sample rate ATV supports nowadays is 48KHz which means your 44.1KHz music is rate converted dynamically when it's output, which will have some effect, although it may be slight. It's still very good with lossless source files.
There is no specific issue with the output quality of the optical out connection. It's still digital at that point. It's really what you plug into it that dictates what happens next.
Once you have the ATV playing your music, you need to convert the digital audio to analog for your headphones somehow. There are a range of different DACs which can do that, and they will vary in quality and price so you have to choose something that fits your requirements and budget. Also, the analog signal will need amplification somehow. Normally you would connect the optical out to a DAC and then the DAC to a stereo amplifier, or connect the optical out directly to a receiver which has a digital input. Then you would plug your headphones into the amp or receiver. I'm not completely clear how you are intending to do this part.
Alternatively, you could just plug your headphones into your television. I'm assuming you are connecting your television via HDMI, and HDMI carries the audio too, and your TV will convert it from digital to analog. That way, you would not need anything else.
As to how to get the audio to your ATV, you have two opposing methods. You can push it using Airplay, when you do that ATV stops whatever it is doing and plays the music you are sending. Or you can pull it using Home Sharing, which is when you tell ATV about your iTunes library and it can play those files itself. So the methods are:
- Push using Airplay from your phone, using the 256 Kbps files
- Push using Airplay from your computer with iTunes on it. This would be from your lossless library files, and you could control it using the remote application on iPhone if you wanted to. (As well as controlling ATV, it can control iTunes on your computer).
- Use the ATV itself to pull the audio files from your iTunes library. Set up home sharing on your ATV so that it can see the library on your iTunes computer. Then, you can use the ATV's UI to play your library files on ATV. Either using the ATV remote, or the iPhone app.
There are pros and cons for all of these. In practice I use all three, depending on what I am doing. If I don't have the computer on at all, and just want some background music, I just play 256 Kbps music straight off my iPhone to ATV using Airplay. Quality isn't bad. If I want to listen to music properly (and usually quite loud as ATV is connected to a big ass stereo) then I play the lossless files which are in my iTunes library on my computer. Either in iTunes directly pushing via Airplay, or else using ATV to pull them from the iTunes library with Home Sharing. So there are a lot of ways of achieving the same thing.
The bottom line is it depends how important the quality is to you as to which is the best way, and how flexible you want to be about playing music. I hope I haven't confused you too much, as it's a bit of a can of worms
