Its all pretty much bolt in but it is a lot of work and I personally wouldn't consider it unless I had access a wrecked 4wd XJ with all the parts you will need. You'll be surprised at the various little parts that you'll find that you'll need.
The 2wd and 4wd AW4s are different, the difference is in the tail shaft. You can swap the tailshaft but its something that needs to be done by someone with experience in doing that. Aw4s are pretty plentiful in junkyards so I'd probably just get a 4wd transmission.
That being said, you're probbaly better off just getting a 4wd XJ to start with. There are plenty of them around and the difference in price isnt that much different. That is unless you have an exceptionally nice XJ, sentimental attachment, or you just are looking for a project.