Reverse Polarity Optoisolator
This circuit works:


when the battery is installed correctly, a current flows through the optoisolator's LED to ground, and the output is on;
when the battery is reversed, a current flows through D1, and the optoisolator is off.


But if you replaced the optoisolator with a transistor, then:


when the battery is installed correctly, a current flows through base and emitter to ground, and the output is on;
when the battery is reversed, a current flows through D1, and the transistor is off. Because of the voltage drop over D1, the transistor's base will be about 0.7 V below ground, which is harmless.


So the optical isolation does not actually protect against anything.



Using a 15 V Zener at that place is pointless; the optoisolator's LED will already clamp the voltage to about 1.2 V. D1 is useful only for reverse voltage protection, and for that, a 1N4148 is enough.

R2 should be larger; 20 mA is much more current than actually needed. (Especially when you're using a plain transistor.)