How big is that engine? Have a chat to scottybobcat, he put a genIII into his d22. Good luck fitting that engine into a d40! As far as I know you're going to run into the following problems:
Diff ratios, ecu, wiring loom, engine bay size(probably your biggest hurdle) gearbox etc.
You'll probably need to fit a body lift before you can look at doing this.
Keep us posted with your research and progress!