To read the codes, all you need to do is follow the instructions from previously posted thread OBDI code how to. But this will only give you the codes. A real time scan or scan of parameters which caused the codes (freeze frame) will tell you more of what could be the problem. Basically, with a freeze frame, the data shows what was happening to the engine or emissions system when the code was switched on.
As for why the car will run fine for a while after disconnecting the battery. The engine goes on a certain set of parameters at the start, then it learns what is happening and compensates for it until it can't and that is why it starts to do the "bang shift" again.