I'd be chasing the P0313. That's a misfire in cylinder #3 and that can cause your rough running symptoms.
P0430 is probably a bad catalytic converter. Big money.
P0365 is probably cheapest of all. Cam sensor or wiring.
I'm not an expert with BMW but that's my .02