Pex lines generally feed into the valve body, which should be firmly anchored, and the shower head and tub spout metal plumbed (I know plumbers who do it that way).
If they are not, and the spout and shower head are pex fed, then they should be firmly anchored on blocking. If the spout is pex fed it will most likely be held in place with a set screw, as mentioned below, which will allow you to pull the spout out of the wall far enough to undo it. Hopefully.
As I said, most plumbers I know make those connections with metal just to ensure proper stability of the valve, shower head, and spout.... but may the odds be ever in your favor.