This switching process can be accomplished as shown in Figure 1.
A DPDT switch is used. Of course, this switch can be replaced by the contacts of a relay.
An important factor to observe in this circuit is that the batteries must have the same voltage. If they are different, the current tends to How through the lower voltage battery when they are in parallel. As there is nothing in the circuit to limit this current, the batteries can be destroyed. Keep in mind that the same block can be used to connect any other voltage source (or signal) in series or parallel.