If you have British passports, you will not require a visa.
You can do a Transit Without Visa for your first arrival, which allows you up to 144 hours in Shanghai and vicinity.
On your return, you will simply transit - although SQ and BA are in different terminals - you may again require a
TWOV to change terminals.