THe US actually did have several opportunities to establish good relations with Iran following the 9/11 attacks. If anyone remembers, Iran actually condemned the terrorists of Al-Queda, as the Death to America chants were replaced by death of the terrorists.
Iran actually did cooperate with the US during the War in Afghanistan. Remember, during that time, Khatami and the reformists were in power, not Ahmadinejad and the hardliners.
However, US officials accused several hardliners in Iran of harboring terrorists who had crossed over from Afghanistan, and relations soured when Tehran responded that they did not know where they were and therefore could not turn them over to US forces. That led the United States government to believe that Iran was in fact helping the terrorists, as George Bush had described in his infamous 2002 ‘Axis of Evil’ speech.
In 2003, the REformists again tried to strike up a deal with the Americans, after they had successfully invaded Iraq and were at the apparent height of their power in the Middle East. Fearing invasion of the US, the Reformists used a Swiss diplomatic channel to outline what was called the Grand Bargain’, a document which stated that Iran was willing to work with the US in providing stability to Iraq, along cutting back on its ties with Iranian sponsored guerilla groups such as Hezbollah, its nuclear policy, and even moderating its rhetoric against Israel.
In exchange, they pushed for security guarantees, an end to economic sanctions and a promise never to push for regime change. However, the US never responded to this proposal, as the State Department believed that the reformists wouldn’t be able to come through on their promises, and since the situation in Iraq was going so well at the time, felt that they didn’t need to negotiate with Iran. Since the ‘Grand Bargain’ had fallen through, along with previous attempts to negotiate with Washington, the reformists in Iran lost all credibility, and soon afterwards, were replaced by a hardliners led by Mahmoud Ahmadinejad
And I'm sure you know what happened from there.