i need to replace the engine in my ford ranger is it possible to use a 4.0 engine instead of a 2.9?
The fact that a 4.0-liter engine was not an option for an '88 Ranger makes the swap that much more difficult. There's going to be lots of brackets, wiring harnesses, mounts, and more which don't match up with the original engine.
As far as parts and labor are concerned, it all depends on where you buy the parts, who does the work, and how involved it gets as the job progresses.
You may want to check out http://hollanderinterchange.net/resources.php
These are the guys who write the books for the junk yards that tell them which parts from one car or truck, will fit in another.
It may not be worth the effort, but it's your call.
Hope that helps.