I went through similar issues on my X5 last year. I was getting lean fuel trim on both banks. I first replaced the O2 sensors on both sides. The change interval is about 100k miles. If you don't have a record of replacing them I would suggest you go ahead and replace the upstream O2 sensors which are before the cats. It is unnecessary to replace the after cat O2 sensors because they are only used to determine if the cats are working and will not cause your issue. Also, since they are exposed to much lower temps they tend to last much longer.
Since you swapped in a known working MAF that is unlikely to be you're issue.
If the O2 replacement doesn't solve the problem the next possibility is a vacuum leak after the MAF so that un-metered air is getting into the system and the computer is not able to add fuel to account for it. One method to check this is to lightly pressurize the intake system to a few psi or so and spray some soapy water at connections. I found that the connection just after the MAF was leaking on my car and replacing the internal rubber seal fixed it. There are other methods using a smoke generator but hopefully you won't have to go to that effort.