The letter x is very versatile indeed, and takes quite a few sounds in Portuguese. Here are a few rules as to how it sounds, which will cover quite a few, maybe most, words.
Letters ex followed by consonant: in Portugal and Rio the x sounds ʃ as in ashamed if followed by unvoiced consonant (as in explicar) and Ʒ as in pleasure if followed by a voiced consonant (as in ex-marido). Elsewhere in Brazi the x generally sounds s insteas of ʃ and z instead of Ʒ. These are actually the rules that also apply to the pronunciation of the letter s when followed by consonant. You can see a question and answers on this topic here and learn a simple test to identify voiced and unvoiced consonants here. Bu If you don’t know about voiced and unvoiced consonants don´t worry: your vocal system will automatically take care of that for you.
Words starting with maxi like maxilar, maximal: ks as maximum, with at least on exception: in máximo the sound is s as in classmate.
Words with the suffix ixo or ixa and derivations, like prolixo, prolixamente: ks again.
Words starting with ex followed by vowel like exame, existir, exoesqueleto: z as in *maze. This includes words with the prefix exo that you mention (comes from Greek, meaning out, outside).
Words starting with hexa (meaning six). Now for the surprise. Priberam gives both z and gz as possible pronunciations! Dicionário da Academia das Ciências de Lisboa gives gz as the only pronunciation. But — I’m with the other native speakers here. I don’t recall having heard any such word pronounced with a gz, and I certainly don’t do it myself.
The words above mostly came late into the Portuguese language from Latin and Greek. Most other words with x in it (unless I’m forgetting an important class) are older and more everyday words, and the x sounds ʃ. Most words. There are lots of exptions.