The fitment info you have been given is correct:
2.9 engine will bolt up to 2.9 or 4.0 trans
3.0 engine will bolt only to 3.0 trans and vice versa
4.0 engine will bolt to 2.9 trans, or late 4.0 trans if you want it to live.
Just slightly unclear from your post what engines/transmissions you have, and what your build vehicle is, so I'm going to assume its the 87 B2 in the interests of making this a generally useful thread.
The early rangers (and B2s, I assume - will let someone else fill this in) started coming with the fuel-injected 2.9 as an option to the inline 4 in I believe 1986 (for sure by 1987). The automatic transmission was the A4LD 4-speed overdrive, featuring a 2-wire electronic control (only one internal solenoid, the converter lockup) until 1988, when this was changed to a 3-wire control (2 solenoids for converter lockup and 3-4 shift, respectively). The early A4LDs were somewhat light for the power being put through them (especially the 4L, later). Through the years up to the replacement of the A4LD in 1995.5, the internals of of the A4LD were beefed up in revision after revision, both at the factory and by rebuilders. The last version, factory issued from 1993.5 on behind the 4.0s, was the strongest and best version.
Starting in 1990, the 4.0L V6, a muscled-up version of the 2.9 Cologne V6, became an option on Rangers. The completely different, engineered in North America 3L Vulcan V6 engine also become available about this time (late 1990, 1991 for sure onwards); it co-existed briefly with the 2.9 until the 2.9 was phased out in 1992 (Not sure the 3.0 was ever offered in B2s and kinda think the 4.0 was only offered in the explorers that replaced the B2, but will let someone else field that one)
So, if you're looking to re-engine/trans a 1987 B2, the no-hassle choice is a 2.9 and an early 2.9trans (pre-88 one with 2-wire electrical hookup) Any later 2.9 transmissions, including the later beefy 4.0L ones, will require some electronic skulldudgery to mate the 2-wire to 3-wire shift/lockup controls. The 4.0 L transmission would be an upgrade behind a 2.9, but will require some reading up to figure out eg: which torque converter, flex plate, bellhousing cover plate and starter to use (although the 2.9 and 4.0 share a bellhousing bolt pattern, the 4.0 has an integral aluminum oilpan that the bellhousing bolts to, whereas the 2.9 has a ordinary pressed steel oilpan that in no way serves as a bellhousing mount) Also the shifter changes from floor to steering column somewhere about 1989, and this requires some accomodation while you have the trans apart checking for debris and changing the filter.
Likewise if you're contemplating a 4.0 engine transplant, do yourself a favor and grab a parts truck so you can rob the transmission, mounts, Radiator/oilcooler, computer, engine compartment wiring, air intake box etc.
Same for 3.0 L, which will of course be entirely foreign to your 1987-era ranger or B2
Oh, yeah, if this is for the B2 you need the 4WD version of the trans.
Good luck