The old codes, dont worry about.
But of course you go a PPI, right??? Pre Purchase Inspection???
You need to replace the EXHAUST camshaft position sensor, bank2. I kind of recommend replacing all 4 CPSs (two intake, two exhaust) as they tend to fail. The run about US$80 per, more or less. PITA to install. Lots of DIYs.
The crankshft error is most likely due to the CPS- once they loose track, you'll see crank errors.
A few things to consider: O2 sensors, MAFs, VANOS Orings, Fuel Filter.
But replace the CPS and go from there.
and by far the best online forum for M5s is M5Board dot com
Keep it as simple as possible...but no simpler.