Jorge, you gotta do you, but nothing is more expensive than a cheap BMW, and a free BMW is probably the most expensive of them all..
I suggest you walk away and sell this project to somebody else.
In my opinion, it’s going to cost you $3,000 minimum to get this on the road in safe condition. And that assumes you do all the work, which will take you 3 weeks to a month working nights and weekends..
having said all that,
For the easiest plug and play replacement, you want an M52TUB28.. it came in 328i, 528i and Z3 2.8 from ’99-‘00…You can find an engine from LQK or Car-part.com, but if you get a warranty, read and follow every word. Buying a running parts car with engine is usually the cheapest option. And pulling the engine out of both cars might give the experience you need to install it.