In order to try understand ME, forget the US. This is a shia-sunni thing, and has been going on for the last 1300+ years. Names of participants may change, but it's still a shia-sunni conflict.
You've probably heard in the news that the "Iraqi Army" and the Kurds have started a major offensive to liberate Mosul from ISIS. Here's a picture of "Iraqi Army" SP artillery around Mosul taken today.
You'll notice they're flying token Iraqi national flags and huge black and green banners. These are shia sectarian banners praising Ali. You might have seen them in those Hezbollah videos.
So it's not "Iraqi Army" vs. ISIS but shias vs. sunnis - salafi sunnis to be precise.
The "Iraqi Army" (supplied and trained by the US, but taking orders from Tehran) is trying to capture territory around Mosul and finally fulfill the ambition of the tribes from Zargoz mountains - unbroken shia territory from Tehran to Mediterranean. The Kurds, nominally sunnis seems to have thrown their lot with the shias - I guess they're really tired of being massacred and killed by their nominal coreligionists.
It's weird with the Kurds - ethnicity takes precedence over religion in the eyes of their enemies. For Turks a Kurd is a Kurd first and foremost, not a fellow muslim. And that's pretty much a death sentence. Remember how Saddam (sunni) gassed Kurds (nominally sunnis) alongside shias?.
Iran's Mediterranean gambit is nothing new, as I have written here before - it predates islam by 300 years. Many Persian and Parthian emperors invaded the Roman province of Syria for this precise reason.
Iran's geopolitical goals match those of the US. Like it or not, those shias waving sectarian banners are fighting "terrorists", although they've would have used the terms "sunni infidels".
Iran is not waging a proxy war against the US, it is primarily waging a war against Saudi Arabia, the main driver and financier of the sunni revival gripping the muslim world, a war in which the US is being dragged on the side of the terrorists partially out of inertia and partially out of cluelessness.
Ultimately, everything terrorism related comes back to Saudi Arabia. Every terrorist attack comes back to Saudi Arabia (9/11, San Bernardino) or more often to Saudi funded mosques in Pakistan and Europe.
Iranian regime is always worried about the "Saudi infantry" - derogatory term for the US armed forces - and that the Saudi lobby will coax the clueless Americans into military action against them. They drew their lesson from the perilously close call with the Ahmadinejad presidency, that a having a hardline fool for a president coupled with intense pressure on Washington (McCain's "bomb Iran" slogan) can get them bombed, hence the Nuclear Deal and the slow detente with the US.
Don't forget that during the Iraq-Iran war US shot down an Iranian civilian airliner and sunk an Iranian frigate alongside several smaller warships, so one can understand their desire to acquire defensive anti-maritime capabilities in the Persian gulf.
To conclude, Iranian regime is smart enough to realize that challenging US military supremacy in the Gulf is suicidal, and they're definitely not suicidal. If that was not the case, they would not have backed down during those incidents listed above.