Markets are not at all perfect or optimal because there are always some stakeholders excluded. However, markets are still able to include MORE stakeholders and provide more truthful information about the stakes than other means of determining who gets what in society, which means they're more efficient.
Regarding labor markets, I think you're being too harsh on life of serfs. There's actually little basis for saying that life is any better today for commoners than it was then for commoners in feudal periods, except in absolute material goods (which, for many, is everything of course). As the eminent economic historians Fernand Braudel and Karl Polanyi have written about at length, serfs may have been more or less tied, on the one hand, to the land they were born to (and with immigration restrictions today, has that really changed?), but on the other hand, state-level political authorities had almost no role, least of all economic, in their lives which revolved almost entirely around communal and family-level production and distribution. State power intervened in trade, not in production, most of which was agricultural.
Quite true about externalities and market failures. However, that only addresses what's wrong with markets, not what's right about any other system. Externalities are also a problem in ANY system of figuring out who gets what in society, and, because of the information asymmetry problem, a system that restricts sources of true information can almost never be better at accounting for externalities than a market-based system.
Bluntly put, Joe Q. Median has a vote in a parliamentary system. In a great many parts of the political economy, he has no vote under a market system, because Joe Q. Median is not a market actor. So for the majority of the population accountable democratic government is superior to market economics simply on the count that the latter disenfranchises them while the former does not.
A lot of successful regulation is about cutting the big market players down to a size where Joe Q. Median can become a genuine market player. But this requires continual political vigilance, because markets are better at forcing market actors to cease being market actors than they are at making room for new market actors.
And then of course there are the sectors where there can be no "market" because the logistics of the production won't permit it. That could be due to the returns on economics of scale being sufficiently high that any gains from market forces would be offset by the cost of maintaining sufficient numbers of separate systems to have a meaningful market. Or it could be due to the risk of cascading failures making the independence of market actors impossible. Or it could be due to the ability of large market actors to take the political system that maintains the market hostage. Or some combination.
- Jake If you only spend 20 minutes of the rest of your life on economics, go spend them here.