The O.E.D. says that the origin of the word is "unascertained", however one of the best theories is as follows. In the 1600s the Germans referred to the Dutch as Jan Kaas (John Cheese) The English picked up the term, (pronouncing it Jan Cheese) and used it to describe Dutch pirates and later to Dutch settlers in New York. Following that, during the American Revolution, the Southerners used 'Yankees' perjoratively to describe Northerners. Then, during WW1 us Brits used the term when referring to any American. Like tea from China some things sound far-fetched but I doubt if you will find a better explanation ........ unless Darth Vader gets on the case.
It is also possible that it came from a Cherokee Indian word, 'eankke', meaning 'slave/coward', but it is far more likely - as Mike says - to have come from Dutch. Their name, 'Janke', meaning 'Johnnie'...'J' is pronounced like 'Y' in Dutch, so it sounds more like 'Yanke' to British ears...is also a conceivable source.