When to get out of Iraq
As soon as humanely possible. And yes, that is humanely, not humanly. :)
It's going to be a mess whenever we leave. The longer we stay, the bigger the mess is likely to be, the deeper the divides within the country, the longer and nastier the civil war that will surely follow our exit will be.
But that's just the military we're talking about. Getting the military out (and keeping it out of Iran) makes good sense. Both for their country and ours.
After that we need a Marshall plan for the Middle East. We destroyed Iraq's infrastructure. We should rebuild it. That's, no doubt, quite a bit cheaper than keeping our military there for a few more years or decades. In fact, we could probably fund a lot of reconstruction (after the civil war peters out) and still have plenty left over to rescue social security, increase funding to schools, and so on.