Alan Schwarz of the New York Times reports about Pat Venditte, an ambidextrous relief pitcher for the Creighton Blue Jays. Venditte has a specially-made glove that enables him to switch pitching arms depending upon the batter.
Greg Harris, normally a righthander, was the last major leaguer to switch pitching arms during a game, back on September 28, 1995 in a meaningless game.
According to Peter Morris' book A Game of Inches: The Stories Behind the Innovations That Shaped Baseball, there were three pitchers in the 19th century who were confirmed to have "switch-pitched" during a major league game.
They were: Tony Mullane in 1882, 1892, and 1893 (he was normally right-handed), Larry Corcoran (who tried it in 1884 for one game), and Elton "Icebox" Chamberlain, who was reported to have done it at least once in his career and may have thrown pitches to home right-handed and pickoff throws to first left-handed. This is of course easier in an era when pitchers did not wear gloves.
It's not know if the 19th century pitchers were seeking a platoon advantage or just a way to rest their better arm.
The NCAA's Official Rules of Baseball 9.02 (k) states
A pitcher may not pitch both right-handed and left-handed to the same batter in the same at-bat.
The penalties for this are a balk if runners are on or a ball. The pitcher has to declare first which hand he will throw with. Although this rule is not formally in the professional rules, it is what umpires are directed to do.