Sailors who had had plenty to drink were in this condition. The vinegar may refer to the acidic form that cheap alcohol adopts when drunk, or it may be the vinegar that sailors drank to ward off scurvy.
There's rarely one answer to the question "where/how did this phrase originate." Shane offers a plausible answer and he may well be right. Here's a little more information about the phrase anyway.
"Vim and vigor" is a common, more polite way of phrasing a similar idea. "Vim and vigor" implies youthful energy and, to a degree, innocence (or good intent). "Piss and vinegar" implies devilish or mischievous behaviour and general vitality. The two phrases are very similar in meaning, but they imply different things, so they shouldn't be used interchangeably.
"Piss and vinegar" may be a corruption of "vim and vigor" (they have similar sounds - when I was young, I though "vinegar" and "vigor" were the same thing!) Both phrases have been around for a long time - I know Steinbeck used "piss and vinegar" in Grapes of Wrath, but the phrase was probably in colloquial use well before Steinbeck wrote his novel.
As a final note, "piss and vinegar" is considered vulgar, so is rarely used in "polite" conversation. It's a lot of fun to use it, though - it's a satisfying way to express frustration with someone's antics.
The Oxford English Dictionary's earliest citation for it is from its 1942 mention in The American Thesaurus of Slang , but in Steinbeck's 1938 The Grapes of Wrath. there appears: "'How ya keepin' yaself?' 'Full a piss an' vinegar.'" If Steinbeck had a character use a phrase in speech and didn't gloss it - (make it less 'vulgar') - then the phrase had to have already been familiar for some time before he recorded it. There are also plenty of citations going forward from that date, all the way up to Bart's declaration in a 1994 episode of The Simpsons: "I'm full of piss and vinegar."
However, we still haven't turned up anything earlier than the Steinbeck citation, which makes it hard to know where the phrase comes from. There is certainly a similar expression with the identical meaning, "full of beans," which goes back to 1854. There's an expression, "full of piss and wind", which means 'full of blustering talk; pretentious' that dates to 1922. There's also Kyne's "He's full of pep and vinegar" (They Also Serve, 1927) that may indicate a euphemistic treatment of "piss"; certainly the sense of vinegar alone meaning 'vitality' was already part of campus slang in the 1920s.
It could just be that the 1920s provenances of vinegar meaning 'vim',"piss and wind," and "pep and vinegar" all combine to mean that some slick-haired co-ed came up with the combination of pungent liquids in the expression. In fact, they've been combined before: there is an expression "to piss vinegar" that goes back to 1602, meaning 'to be miserly'. This gave rise to the 18th-century "vinegar-pisser," a 'miser'. If there is any connection between these meanings and piss-and-vinegar vitality, it seems exactly the sort that a college student might make.