I cut open the key on my E39 facelift, then I used an old trick of rubbing the battery vigorously on a hot/warm stove plate, thereby re-energizing the battery a bit...then I meassured the voltage with a voltmeter, ....thereafter I connected a normal AA battery or two (cannot remember the actual amount), in series, thereby in effect giving the battery a bit of a re-charge again
that was 2 to 3 years ago...hasn't missed a bet since then.
coding...youtube is your friend.....some sequence of sitting in the car, pushing the hold open down, series of clicks, doors lock and unlock...and the key is coded....the actual sequence not known now anymore and too lazy to search youtube, but i can tell you its as easy as pie.
the only bad thing is that the plastic holder of the key bears the scars of being opened with a Stanley knife once upon a time.