You’ll need an Toslink optical cable, glass or plastic depending on your budget, and a DAC with an optical input. For output from a TV, a relatively inexpensive DAC should be fine, have a look at models from Schiit and Topping. Then run a pair of R/L analog cables from the DAC to one of the analog inputs on the Mac. On the TV you’ll need to go into the audio section of the settings menu and choose the optical output in place of the TV speakers.