Key B battery is probably dead since it won't unlock/lock and why it would start the car.
Key A has a good battery but the EWS transponder thing is probably bad. happened to me. first thing was to try and get the key to communicate with the car again. forgot how to do it (google it) but it's something like holding the lock button for a certain time, putting the key in the ignition, etc, etc. if that doesn't work, you'll have to probably get a new key and sync it up.
try this site, method 1 or 3.
or this method from e46f
After I bought a 2001 325i with one key I bought a 2nd one from the dealer. I had a very hard time finding correct instructions to reprogram the car to recognize the new key. The key type I have is the rechargeable, non-replaceable battery, and has 3 buttons: 1) unlock; 2) lock; 3) open trunk
Have all your keys with you when you do this. This works:
Get in and close all the doors.
Turn the ignition to "Run" and the turn it off quickly. (Note: this is the middle position for the key, not "Accessory" or "Start")
Remove the key.
Hold the key up to your left shoulder.
Hold down the UNLOCK button and Press the LOCK button (center button) 3 times. After you release the LOCK button the third time the doors will lock to confirm the operation.
Quickly repeat the key-button-clicking steps (ONLY) for all your other keys. Note: Do not put any of the keys back in the ignition until you have reprogrammed all your keys