I've actual made a schematic of this for a project I'm working on for the same purpose. You can take a look at it if you want to use it as a reference.
Q1 & Q3 break the series connection of the batteries. When the Gate of Q2 is LOW, Q1 & Q3 conduct. When the Gate of Q2 is HIGH, Q1 & Q3 stop conducting. The gate of Q2 is controlled by the arduino.
Q8 & Q9 work just like Q1 & Q3. Their purpose is to break the connection from the main circuit. The only difference is that the gate of Q12 is controlled by the input voltage of the USB connection.
Q4 is controlled by the arduino and it connects the negative terminal of B2 to GND.
Finially, Q11 & Q5 (also Q13 & Q6 since they're the same) are switches that lets current flow from the output of the charging IC. In this schematic, each battery has it's own charging IC, so keep that in mind. These FETs are controlled by the gate of their respective N-FET. When the Gate of Q10 is LOW, Q11 & Q5 are not conducting. And when the Gate of Q10 is HIGH, Q11 & Q5 will conduct. The Gate of Q10 is also controlled by the arduino.
In the program, I have it to where I set specific gates high in a specific sequence to prevent any short circuits:
And when the USB Power supply is removed, the way I return from parallel to series is as follows:
I hope this helps you with your project.