Sounds like the Maf has failed if it runs with it disconnected as it runs on default settings, you could try cleaning it with Maf spray cleaner and then plug in a code reader that can display live data and take a look at what the Maf is doing with the engine running. If you replace it only use oem brands like Bosch or Seimens do not use cheap ebay Maf's they don't work, been there and ended up going oem, got a refund on the cheap one thankfully. Same for all other sensors like camshaft and crank sensors always go oem, have had success with HASS brand camshaft sensors in the past so that is a cheaper option that works. Sophers BMW in Lincoln are a good source of spares as they give Forum members a discount but you have to ask for it, they post items out to you so just a phone call required. Use Realoem website to look up part numbers, enter the last 7 letters and digits of your Vin number and it will bring back details of all parts fitted to your car when it left the factory.
RealOEM.com BMW Parts website. This site can be used to look up BMW part numbers and approximate part prices. The Parts are grouped into diagrams and diagrams are grouped into categories and subcategories
www.realoem.com