The aphorism was coined by the Dallas Cowboys quarterback, Don Meredith, who later became a sports commentator for the TV show Monday Night Football in 1970.
17 December 1970, Ada (OK) Evening News, pg. 7, col. 1:
Howard: “If Los Angeles wins, it’s a big one, but San Francisco is still very much in it.”
Dan: “If ifs and buts were candy and nuts, we’d all have a merry Christmas.”
Howard: “I didn’t think you’d remember that old canard.”
Dan: “Is that what it was?”
Source: Barry Popik.com
The 1970 quip soon became Meredith's catchphrase, but it was a modern and comical twist on a much older proverb dating from the 19th century
“If ifs and ands were pots and pans, there’d be no work for tinkers’ hands”
This proverb is used as a humorous retort to someone expressing a forlorn regret (e.g. if only I had the money...) or an unrealistic and perhaps over optimistic condition (... and if I had the right connections, I could be famous.)
The earliest example I found on Google Books is dated 1845 from The step-mother by George Payne Rainsford James.
“Ay! if ifs and ands were pots and pans, there would be no work for the tinkers.”
@Sven Yargs has discovered an even earlier example, in The New Monthly Magazine and Literary Journal, 1828, from a poem entitled A chapter of Ifs
A Chapter of Ifs
If Ifs and Ands were pots and pans,
’Twould cure the tinker's cares:
if ladies did not carry fans,
They’d give themselves no airs:
If down the starry skies should fall,
The starlings would be cheap:
If Belles talk'd reason at a ball,
The band might go to sleep.
And finally, printed in 1821, an excerpt translated from a poem entitled Hans Beudix by the German poet Gottfried August Bürger (1747-1794)
Are you there, my old fox, with your ifs and your ans?
But I need not remind you, they're not pots and pans,
Else tinkers would starve, (as I learnt from my nurse;)
Still the answer shall pass, for it might have been worse.
The original German poem can be found here: Der Kaiser und der Abt. Maybe someone can confirm if the translation is faithful.
Below is an Ngram comparing the two aphorisms: Don Meredith's “...buts were candy and nuts” (blue line), and the German/British “ands were pots and pans” (red line) side by side in the American English corpus. The time span is between 1968 and 2008. The 1968-72 results for Meredith's coinage are false positives, so it's always wise to take Ngrams with a pinch of salt. No results are displayed for the American rhyme in the British English corpus.
If we expand the time scan between 1835 and 2008 we obtain the following