4.0 has more power and quite a bit more torque but it is also heavier. It will of course outperform the 4banger on the hwy, offroad the differences are not that obvious, but again it is a larger engine so there are some differences.
I'll second that; if geared properly, a 4banger will hold its own to a I6 off road no problem. But on the highway, the I6 will smoke you!
As far as prices, it depends on model, year and condition. I bought a nicely built '94 YJ for a friend a few years back (33's, 4" lift, I6, Sahara model, Ox Lockers, Mean Green Alternator, Mean Green Starter, Flex-a-lite fan, soft top, bumpers and a few other goodies) for $4.5K in south FL. If you get a built one, you will probably have to drop less coin in parts, but more likely than not, the rig WILL have been wheeled (so more risk of hidden damage). A stocker will be a bit cheaper, but you will need to drop more coin to build it up.
As far as which model is better offroad, both the YJ and TJ are VERY capable, even in stock form. As far as engine, also both are very capable offroad. The main difference in engine I feel you will get ON road, but the I6 will always have more torque (more weight also). I personally prefer the YJ because it is easier to lift than the TJ (you dont have to worry about long arm kits), but htat's just personal preference.