I would think MAF(mass air flow) sensor is your problem, common issue on 4.0l and Rangers in general.
Good read here: Ford Ranger Mass Air Flow Cleaning, Removal and Installation
MAF sensor is the main sensor used by computer to set the air/fuel mix.
It is a pretty simple device, a wire is heated, as air flows passed the wire it is cooled, the amount of cooling tells computer the amount of air coming into engine.
Computer also has an air temp sensor(IAT) to compensate for outside air temp and cooling of MAF wire.
Over time the MAF wire can get a coating on it, it acts like an insulation on the wire so actual air flow data is incorrect.
Good news is that these are very easy to clean, don't use Carb Cleaner, MAF Cleaner or other electronics cleaners are OK.
The MAF sensor is on the air cleaner housing, there is a large Plenum(air tube) connecting MAF to Intake Manifold, if that plenum is cracked or its gaskets are leaking then MAF data would also be incorrect.