Replacing Multi-turn Toilet Valve
A pipe wrench holding the exposed portion of the nipple should allow you to remove the valve without loosening the joint in the wall.

But be sure to inspect the condition of the pipe.  This appears to be galvanized steel pipe which rusts over time.  If the pipe appears to be rusted severely or is filled with scale, you may want to replace it and even the pipes in the wall.

Note, you may wish to employ a helper to hold the pipe wrench while you unscrew the valve.