i used to have a 320d that done similar to this, if you code read it bet it comes up with can bus faults etc, i tried all sorts codes wouldnt clear, weirdly enough if i unplugged the ecu under bonnet reconnect it would then be ok, it had a hissyfit every couple months like this!! it did also have a pedal related code may well of been my throttle pedal playing up.