Harold Wentworth & Stuart Flexner, Dictionary of American Slang (1960) asserts that peanut has had the slang sense of smallness or insignificance for a long time, but that the plural form peanuts in the slang sense of a small amount of money is far more recent:
peanut adj. Unimportant; little esteemed. Since ca. 1840. n. 1 A small or small-time person → 2 A small vacuum tube about the size of a peanut shell. c1930, electronics use, archaic. [peanut]s. n.pl. 1 Anything, esp. a business venture, which is unimportant, insignificant, or small. → 2 A small amount of money, esp. a small profit. 1941: They got you working for peanuts." [Budd] Schulberg, Sammy, 165.
Robert Chapman & Barbara Kipfer, Dictionary of American Slang, third edition (1995) push back the origin date of peanuts in the sense of "A small amount of money" to 1934.
The earliest instance of "working for peanuts" that a Google Books search finds comes from Edmund Cooke, "Daily Bread" in Appleton's Magazine (August 1907), about a kid selling peanuts and soda pop in the stands at a baseball game:
"Peanuts and pop!" are his work of the day;
Peanuts and pop are my portion of play.
Each in his own way from bottom to top,
We're all of us working for "peanuts and pop."
Never enough in bag, bottle, or store,
But each of us bleachers is looking for more.
But Wentworth & Flexner seems to be correct that the phrase "working for peanuts" did not become idiomatically common until the early years of World War II. For example, from a glossary of slang terms in Punch (1939[?]) [combined snippets]:
This expression springs from the fact that most clerks, however inefficient, pride themselves on being miserably underpaid. In fact they consider themselves to be working for
Peanuts. Small change; a pittance. If instead of being a clerk one is a travelling salesman, his situation is better—at least it is in those cases in which he not only receives the weekly insult plus commission, but is able to garner a little extra tin (money) through his
Swindle sheet [expense account].
And from Ray Brock, Nor Any Victory (1942) [combined snippets]:
"...Meantime there's no point in my attempting to negotiate with the Press Wireless people in New York. I don't know them. And of course, with my little exhibition of temper, I've given our friend all the cards he needs if he wants to play them. Moreover, I really don't give a hang. I want to get back in the news so badly that I think I'd work for peanuts to do it."
Although Wentworth & Flexner says that peanut had the slang meaning "Unimportant; little esteemed" by around 1840, none of the nineteenth-century slang dictionaries I checked listed the word in that sense. Perhaps the most interesting slang use of peanut in that century was as part of the term peanut politics. John Farmer, Americanisms—Old and New (1889) has this entry for the term:
PEANUT POLITICS.—A peculiar habit of the pea-nut ... is that of burying its pods underground after flowering, a process by which the nuts are ripened. The term peanut politics, therefore, is a popular allusion to describe underhand and secret tactics.
Update (April 7, 2018)
A series of Elephind searches for "work/works/worked/working for peanuts" yields one interesting and fairly early instance in which the expression is used in its literal sense. From "A Diet Farmer's Experience," in the Claude [Texas] News (April 2, 1937):
"I nearly always stay on top with peanuts. I plow them up when mature, then drive down the rows and thresh off the nuts over the back end gate of the wagon as the vines are shaken and piled. I bale the vines for hay, Those not threshed are baled with the nuts on. Neighbors sometimes need peanut seed or want them for eating purposes and are glad to exchange work for peanuts or buy them outright.
A flurry of figurative instances of the phrase begins in 1940. Here are the four earliest such instances drawn from Elephind searches.
From "Endowment Dilemma," in the Stanford [California] Daily (March 5, 1940):
But students will not go where the professors are childish or where the equipment looks like the remains of the 1906 earthquake. It just isn't logical.
And the good professors nowadays aren't working for peanuts. Nor can you buy classroom equipment on the FHA.
From Harrison Carroll, "Behind the Scenes in Hollywood." in the [Honolulu, Hawaii] Nippu Jiji (March 14, 1941):
Sweet triumph for Rita Hayworth to come back to Twentieth Century-Fox at the price she's getting to play the role of the siren in “Blood and Sand.” A
At one time, Rita was under contract to this studio, working for peanuts. She played with Jane Withers in “Paddy O’Day,” in “Dante’s Inferno” and a few other pictures, then was let go.
From "Zivic Favored Over Cochrane in Title Go," in the San Bernardino [California] Sun (July 28, 1941):
Fritzie Zivic, Pittsburgh puncher who worked for peanuts when he was last seen here on his way up, was the 4 to 1 choice tonight over Freddie (Red) Cochrane in their 15-round welterweight title collision tomorrow.
And from Harlan Reed, "Tough Guy," in the San Bernardino [California] Sun (August 24, 1941):
The trouble is that you've been flashing dough. and you have to keep on being a big-shot. You can't let the boys down. If you stay in the ring, you'll end up slap-happy, and, if you take a job, that's slipping down the scale.
So you drift into Jake Gilson's mob, along with the other smart boys who aren't sucker enough to work for peanuts when there's heavy sugar just waiting to be picked up.