Quoted from oohlou:This but to be more specific:
Optical is limited to 20 bits depth in most cases where as coaxial and HDMI have 24 bit depth. Additionally some technologies are encrypted and they are only allowed to run over HDMI. So if you have a 5.1 (or anything more than 2.1) sound system you should use HDMI for audio for movies to get the best support for the various Dolby standards. For music it doesn't matter.
S/PIDF has not been limited to 20-bit for a long time - it also can handle 192/24bit just like coaxial, although cheap cables will introduce some errors (which most are not audible and likely you won't even notice). HDMI is definitely a generation ahead though. If you are looking to get the highest fidelity audio, the compressed audio formats Dolby Digital TrueHD and DTS-MA are only possible at their highest fidelity over HDMI. You can use HDMI just for audio, too.
IF you are using DVD-Audio, this uses the highest fidelity audio with almost no compression used at all, so it's already pretty awesome. It's hard to find those discs, but they do sound great