I think the origin of these phrases is from Shakespeare's The Merry Wives of Windsor, 1602:
As for which came first, lucky or charm, I found the charm variation earlier and not of American origin as The Phrase Finder has, but British. This is from The Cabinet Album, 1830 (date check):
And the lucky version I found three years later in The Port Admiral, by William Johnstoun N. Neale, 1833 (date check):
Since these two variations can be traced back to the same time period and the same country, I think it's safe to say they are related and that they both echo Shakespeare.
Edit:
Heck, why not throw a pretty Ngram in for good measure:
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 Cosell: “If Los Angeles wins, it’s a big one, but San Francisco is still very much in it.”
Don Meredith: “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.”
Don: “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”
Oxford Reference
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)
Hans Beudix
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
Best Answer
Results from a Google Books search strongly suggest that the expression originated (in print) in religious publications. At least in my search results, publications of the missionary wing of the Methodist Episcopal Church account for the first five matches, spread across a period of seven years. The earliest of these sources (from January 1910) credits the saying to a Commissioner McFarland, who may be the author of the third article cited below.
From "Never Paralleled in New York," in The [New York] Christian Advocate (January 20, 1910):
From "Japanese Church in Wonsan, Korea," in The [Nashville, Tennessee] Missionary Voice (May 1911):
From Henry B. F. McFarland, "The Man by Man Rise of a Race of Men," in Association Men (January 1915):
From "Woman's Home Missionary Society," in Minutes of the One Hundred and Seventeenth Session of the New York Conference of the Methodist Episcopal Church held in First Church, Peekskill, N.Y. March 22, 1916 (1916):
From Hugh Burleson, "The Progress of the Kingdom," in The Spirit of the Missions (May 1916):
From "A Hint from Harvard," in Harvard Alumni Bulletin (December 11, 1919):
And finally, the cover of American Gas Monthly (March 1920) consists of the following quotation and subtitle:
Basically what we have here is a slogan so successful that in a single decade it went from being a watchword—indeed almost a catchphrase—of a vigorous Christian missionary movement to becoming an inspirational proverb for members of the American Gas Association to contemplate.