Stuffing a V8 under the hood is fairly simple if you have fabrication skills. The problem lies in making it work. The cooling system needs upgrading. The stock transmission must be adapted or replaced. The rear axle will not survive long. The fuel system must be adapted. The gauges have to be hooked into the new sensors, and the starter & alternator must be adapted into the vehicles wiring harness. And if it's Fuel Injected, you need to wire a complete engine harness.
It's certainly do-able, and if you keep it carburated it's much simpler. Personally I'd love to get a complete powertrain from a 5.3 Chev, with their 5 speed automatics. It's a LOT of wiring but do a bit at a time and keep it simple, and you've got 315hp/338tq and better fuel mileage. Swap an 8.8 in the rear to match your upgraded D30 front and it's good to go.
'91 Frankenheep YJ. 4.0, 4" BDS, Richmond 8.8, Titan 12k, 35" KM2's, rust.
'88 YJ, 4.2/4.0 head, +4½" & shackles, BFG 33's (sold)