Usually when someone says they are installing a 4.0, they mean they are taking the entire engine, serpantine accessories, and fuel injection with it. It is possible to just take the long block and put it where the 4.2 long block was, and vice versa. Here are some possible combinations:
1) If you put a 4.0L long block in place of a 4.2 long block you gain the better camshaft and head design and you get roughly 140 HP instead of 110 HP you had with the crummy 4.2L camshaft and head. You lose the mechanical fuel pump and must use an electric one. You have a valve cover that doesn't leak. You'll need some washers in the front of the crank to mount the old belt accessories. It is pretty much a bolt in, quick installation that leaves your engine compartment looking pretty much exactly the same afterward and the car running better.
2) If you put a 4.2L long block in place of a 4.0L long block, which I'm doing in a Jeep MJ Commanche right now, you lose a great deal of power and efficiency because of the poor head design and camshaft. In my case I'm also using a 4.0 head and camshaft with a 4.2L short block, so I actually gain a little bit of power because of the extra displacement. You can still use the fuel injection and everything else that used to be on the 4.0L. You need a cover plate where the mechanical fuel pump used to be. You need a specific year of bracket that doesn't need a boss missing on the passenger side. You need to cut a little bit off the front of the crank to fit the serpantine accessories.
3) If you put a 4.0L in with all the serpantine accessories, you get 190 HP. Carbs are initially very attractive because of how few components are present, but they are very tempermental and pathetically inefficient and unreliable. The extra time it takes to fuel inject gives you a die-hard reliable, efficient system that puts out 50 extra HP and requires little to no extra maintenance. It is alot to gain at the expense of a little bit of clutter in the engine compartment.
4) You can also mix and match components. Fuel injection manifolds can be used with V belt accessories. Serpantine accessories can be used with carb intake manifolds. All the problems that arise are easy solutions. For example, the MPI temp sensor conflicts with the Vbelt pulley with AC but Hesco sells a simple adaptor to move the sensore a few inches away. All of the possibilities are nearly bolt in installations with maybe a grinder cut here or a hole enlarged there.
5) If you make a stroker by combining putting a 4.2L crank into a 4.0L block, you get the best combination.