The solution, I think, is to let go of the middle east, but remain vigilant and involved in world affairs. The bad will the US has accrued among Muslims due to the Iraq invasion and perceived meddling is pretty much irreversible.
These people need to be left to their own devices to sort themselves out. For a while, that will not stop the animosity toward the US, and terrorist groups will look to take revenge for the incursions of the last decade, which is why the US will need to remain vigilant on its own shores, and if needed in allied countries. But the continuing military presence in the Middle East is not solving problems, it is creating them. The only place there ought to be military presence now is at US embassies, which is technically US territory anyway.
I have confidence in the possibility that, like most of the rest of the world, the Middle East will self-correct if left to fester on its own for a significant period of time. People of the region will see the squalor and backwardness of their way of life as the rest of the world moves forward, and will strive for something better, which may be found as an example in China or in the west.