Switching between battery and transformer
simulate this circuit &ndash; Schematic created using CircuitLab

Figure 1. Top: Relay circuit. D3 ensures that the relay drops out quickly when PSU power is lost. (Coil snubber diode not shown.) Bottom: diode circuit.

The lower circuit is simpler if:


The PSU voltage is greater than the battery voltage.
You don't mind the 0.7 V drop of the diodes.