You have two options of overhaul. One is top overhaul and the other is FULL overhaul.
I did the top overhaul to my E36 M40, about 1K Parts + Labour. That was almost 1 year plus ago. If you go for full overhaul, it can go up to 2-3k depending what you change.
Depending what you want, if you just a normal daily driver or who wants reliability, a top/full overhaul would be your path. But if you are passionate owner who wants more from the e30 or m40, you can got the M42 path but it's a transplant. Transplant will never get things perfect like original.
Also, E30M40 is not a car nor engine to be look down. If you do up your engine like new, it would be a pleasure to drive and to own.
Good luck