You may choose an engine from light duty truck class. If your Ford Ranger is California emissions certified then a federal (or 49-state) engine cannot be used. You must only use a donor engine which is also California emissions certified.
You may not mix engine and vehicle classifications which will degrade the emissions certification standards. For example, a heavy-duty engine cannot be installed in a light-duty exhaust-controlled chassis even if they have the same displacement.
As you've already mentioned... make sure the engine and emission control configuration of the engine you will be using is of the same year of your truck, or newer (and to the same or a more stringent vehicle certification standard).
Once the engine change is complete your Ford will need to undergo a complete smog inspection at a State Smog Check Referee Office.