P 1519 & P1522 = VANOS Malfunction : alignment to crankshaft position sensor, time to change timing
P0170 = Fuel System related : fuel trim limits (long therm & short therm) exceeded .
So , you have a timing issue, possible bad timing guides & tensioner, or (and) the VANOS units itself. Second group code (0170) could be related to the miss alignment, or MAF sensor.
Instead of replacing the engine with a used one I would go doing a heads removal/resurface and do a valve job, changing timing parts , Water pump system, and you'r all set with the engine. All this depends on the millage.
The transmission issue could be due to a charging issue (alternator or breakage in the cable somewhere) or transmission itself. It's hard to tel without a proper diagnostic.
Or all together could be due to a electric issue , possible in the ECM area?
Either way I would recommend to find a BMW specialist (not always a dealer) and get a proper diagnostic before throwing money here and there...
JOY = BMW