Are you the one making the box? And someone else makes the circuit board?
If the batteries go in the box, then you should fasten them down so they don't smash other things in the box.
Do the batteries contain acid? Then they should be in their own compartment, sealed off from everything else. A plastic pan should go under the batteries in case of leaking, etc.
Arrange batteries so it is easy to remove and replace them.
It is possible to make a simple circuit which will:
* detect loss of mains power
* close a relay, mosfet/transistor, to send battery power to your components
* detect restoration of mains power
* wait a few seconds to detect whether mains power is stable
* connect components to mains power, disconnect batteries