The classic exposition of a philosophy of personal selfishness redounding to the benefit of all is in Bernard Mandeville's Fable of the Bees (1714), which is subtitled "Private Vices, Publick Benefits."
In Mandeville's telling, a successful society, like a successful beehive, requires the energy and genius that go into activities undertaken by individuals entirely for private gain—an utterly selfish motive—to achieve the by-product of the general improvement of all. This theoretical analysis or description has been characterized by a number of authors as the Mandevillian paradox.
From George Sherburn, ed., Selections from Alexander Pope (1929) [combined snippets]:
The spendthrift and the miser are, it is hinted, not merely opposite but equal in effect. In lines 161–62 (repeated in the Essay on Man, II, 205–6)Pope tells us that out of such extremes comes the golden mean, a statement which is his parallel to the Mandevillian paradox that "private vices are public benefits." This conception recurs intermittently in his work and a note to line 150 of On the Characters of Women in the last edition revised by Pope speaks of the line as "Alluding and referring to the great principle of his Philosophy, which he never loses sight of, and which teaches, that Providence is incessantly turning the evils arising from the follies and vices of men to general good."
From Cecil Moore, English Prose of the Eighteenth Century (1933):
His [Mandeville's] book is more than a mere succes de scandale. The Mandevillian paradox forced the philosophers to reconsider their definitions. If every selfish act of man is vicious, if man is so constituted that he cannot act unselfishly, and if human society is directly dependent upon selfish and vicious conduct for its cementing principle, what place is to be found in the scheme of civilization for virtue? Using virtue in the sense attached to it by the ascetic moralists themselves, Mandeville implies that virtue is neither humanly possible nor humanly desirable.
From John Burrow, Gibbon (1985) [combined snippets]:
Paradox, irony, and ambiguity
It is worth observing here how far Gibbon's ironies at the expense of Christianity, which were discussed earlier, represent a kind of extension, an additional ironic twist, to the Mandevillian paradox of 'private vices, public benefits'.
From Robert Caserio & Clement Hawes, The Cambridge History of the English Novel (2012):
The philosopher Altangi reorients the Mandevillian paradox to suggest that public benefits must be construed as private virtues, and he even anticipates Smith's paradigmatic illustration of the division of labor by referring to the fact that “Not less than ten different hands are acquired [sic] to make a pin" (Goldsmith, Citizen of the World, vol. II, 55–56).
As the Wikipedia article on "Invisible hand" notes, Smith first described 'the invisible hand" in connection with income distribution in The Theory of Moral Sentiments (1759), 45 years after Mandeville had argued for a similar law of unintended benefits.