America certainly had the manpower but was unwilling to commit the levels needed for the task at hand (or else why the need for 'surges'?). Your latter point is what I mean by 'time'. What was needed, before any attempts at 'nation-building', elections, provisional/transitional governments, and withdrawal timetables, was the imposing of basic security and stability. Even if it took years to consolidate, which it surely would. Only the American military could have provided that. At a minimum it would have required a heavy American troop presence on every major urban junction in Iraq and Afghanistan, and whatever manpower was required to effectively secure their borders, with the message being sent out loud and clear that their presence there was indefinite.
However the American public simply doesn't have the stomach to see its sons and daughters committed in such a lengthy project in a distant, little understood land where the primacy of American interests is questionable.