If you can't get the code - it's possible to change a battery without losing the electrics...
Connect jump leads from another car (or battery) to the battery leads, then disconnect the battery leads from the battery, thus powering the car's electrics from the other car, then change the battery, re-connect the leads to the new battery, then remove the jump leads. Be careful that the jump leads and terminals don't touch against anything while you do the swap.