Here you go with only one relay 

Of course don't forget to use some protections maybe someone here can tell you how! because I don't know 
This circuit will work exactly like what you want
The code work on serial display with temperature sensor
int thermistorPin = A1;
int Relay = 2;
float vPow = 4.7;
float r1 = 50000.0;
float r2 = 4400.0;
void setup() {
Serial.begin(9600);
Serial.print("\x1B");
Serial.print("[2J");
Serial.print("\x1B");
Serial.println("[H");
Serial.println("--------------------");
Serial.println("DC VOLTMETER");
Serial.print("Maximum Voltage: ");
Serial.print((int)(vPow / (r2 / (r1 + r2))));
Serial.println("V");
Serial.println("--------------------");
Serial.println("");
delay(2000);
}
void loop() {
float v = (analogRead(0) * vPow) / 1024.0;
float v2 = v / (r2 / (r1 + r2));
int thermistorReading = analogRead(thermistorPin);
Serial.print("\x1B");
Serial.print("");
if (thermistorReading <= 35) { digitalWrite (2,HIGH);
}
else if (thermistorReading >= 40) { digitalWrite (2,LOW);
}
if (v2 <= 2.1) { digitalWrite (2,HIGH);
}
else if (v2 >= 2.0) { digitalWrite (2,LOW);
}
Serial.println(thermistorReading);
Serial.println(v2);
delay(8000);
}
and this code with LCD display 16*2 + temperature sensor
//Enjoy :)
#include
int thermistorPin = A0; //analog pin 0
int Relay = 2;
float vPow = 4.7;
float r1 = 50000.0;
float r2 = 4400.0;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup() {
Serial.begin(9600);
lcd.begin(16,2);
Serial.print("\x1B");
Serial.print("[2J");
Serial.print("\x1B");
Serial.println("[H");
Serial.println("--------------------");
Serial.println("DC VOLTMETER");
Serial.print("Maximum Voltage: ");
Serial.print((int)(vPow / (r2 / (r1 + r2))));
Serial.println("V");
Serial.println("--------------------");
Serial.println("");
}
void loop() {
float v = (analogRead(1) * vPow) / 1024.0;
float v2 = v / (r2 / (r1 + r2));
int thermistorReading = analogRead(thermistorPin);
Serial.print("\x1B");
Serial.print("");
Serial.println(thermistorReading);
Serial.println(v2);
lcd.setCursor(0, 0);
lcd.print(v2);
lcd.print(" V");
lcd.setCursor(0, 1);
lcd.print(thermistorReading);
lcd.print(" Temp");
if (v2 <= 5.39 ) { digitalWrite (4,HIGH);
}
if (v2 >= 5.40 ) { digitalWrite (4,LOW);
}
delay(8000);
}
you need to change some values to be exactly for your needs if you want any help Just let me know
Inside the code there is ONE voltage sensor, Just copy the first one and of course don't forget to change the pin for the second one
This part for resistors you can use any resistors you want But don't forget to change these values
float r1 = 50000.0;
float r2 = 4400.0
NOTE
If the first battery A under your values the relay will disconnect battery A and connect the second battery B while the first one charging, BUT when the second battery B under your values the relay will not disconnect battery B simply because this code only for one battery, you only need to copy/edit the code for the second one
I am interesting to see your project when you finish it good luck 