I replaced both in my '97 Ranger last week, you're in luck.
The one before that cat is located on the exhaust pipe leading down from the manifold. Unscrew it from the pipe from below, then go above and follow the wires to where the connector is just behind the engine, above the transmission. There are two connectors here - do *not* unhook both. Unhook only the one this one leads to - the other leads to the after-the-cat sensor, but there is another connector down the wire. If you unhook both, you can get them reversed and then you'll be in trouble :)
The second sensor is easy to get to, just after the cat. Unscrew it from the pipe, follow the wires, disconnect it at the first connector.
To install, reverse :)
A couple of things to look for:
- Get an "OE fit" sensor. The universal fit sensors will require you to splice off the old connector, and this is a pain in the ass.
- Use the zipties in the new after-the-cat sensor. Make sure the wire does not touch the exhaust, or it will melt in two. Also be sure that it doesn't have enough slack to hit the driveshaft, or it can get caught and pulled out that way.
About 6 months ago, I did a full engine swap on this truck, so I feel like I know its innards pretty well at this point :) I have a 2.4L 4cyl, so the placement may be a tad different on a 4.0.