Simple circuit to detect ac power loss and use dc backup?
Use a relay with an AC coil to enable the output from the wall wart (and disconnect the battery) then, when AC is lost, the relay switches in the battery with it's normally closed contact whilst simultaneously disconnecting the wall wart.

Make sure that the AC voltage rating for the relay coil is suitable for you local AC power.