Welcome to the forum
4.0l SOHC had a problem with the timing chains from 1997 to 2003/4, the newer designed chains, guides and tensioners can be installed and no more problems.
Unfortunately the engine must be pulled to install the rear chain and guides.
All fuel injected engines use an air flow valve, operated by the fuel injection computer, to set idle RPMs, Ford calls theirs the IAC(idle air control) Valve.
The computer opens the IAC Valve all the way for starting when you turn on the key.
Computer then starts to close IAC Valve after engine starts.
The idle is suppose you go up to 1,500+ RPMs on start up(IAC Valve is open all the way), then computer will lower it(start to close IAC Valve) to match Engine's Coolant Temp, cold engine will be 1,100rpm, or higher, it is related to outside temp, colder temp higher idle.
As engine warms up computer will lower the idle until it gets to about 750-800(automatic trans)
The clattering is most likely the timing chains.
The tensioners that keep the chains tight use oil pressure, and when first starting some oil passages may have lower pressure, so tensioners are not tight and chain clatters.
You may want to run a thicker oil, this bumps up the oil pressure a bit, a 20w50 maybe
You could try this when starting
Turn on the key
Press gas pedal down to the floor and hold it down all the way
Now try to start engine
It should NOT start, count to 5 while engine cranks.
Then stop cranking and release gas pedal
Now start the engine
That 5 seconds of cranking should pump in enough oil to get instant oil pressure at the tensioners.
All fuel injected engine computers have a "Clear Flooded Engine" routine
With Fords it is the computer seeing WOT(wide open throttle) voltage with Key on/engine off.
So when you press gas pedal to the floor with key on the computer sees WOT and will shut off fuel injectors to "clear a flooded engine".
This allows you to crank the engine without it starting.
If your engine starts with gas pedal to the floor then your throttle cable has stretched, so you don't have WOT, easy to fix and it will give you more power.
Google: Ranger throttle cable mod
Its the same fix for explorers