for real 5.1 you need 5.1 speakers............a tv will only give you virtual 5.1 audio which might sound like 5.1 but is far away from 'real' 5.1 surround sound. But yes, if that is what you want, then hook up an optical cable and enjoy virtual 5.1. Both optical and HDMI support 5.1 audio.
If you want real 5.1, suggest to invest in a good entry level 5.1 HTIB like the Onkyo HT-S3500.
If the TV is receiving 5.1, it can stream it to the HTIB.
Usually, the source like BDP/settop box checks if the display has capabilities to decode dolby digital 5.1. If it has, then un-decoded sound is sent via hdmi.This can then be streamed via optical to htib.