Orson Scott Card stated it very succinctly: "Science fiction is about what *could* be but isn't. Fantasy is about what *couldn't* be."
Science fiction depicts things that are not yet possible in our world, but which we believe may one day be possible. Usually it involves futuristic technology and/or scientific phenomenon. Super-intelligent robots, deep space exploration, and extraterrestrial life are among the themes that commonly show up in science fiction. Science fiction stories typically take place in the future, but not always: there are ones set in the present or the past (or, in the case of Star Wars, in some undefined setting with no direct relationship to our world).
Science fiction that was written in the past has often become outdated, as what it describes as "the future" is now the past. That doesn't mean it becomes irrelevant: George Orwell's "1984" is as relevant today as when it was first published in 1948.
Some past science fiction books become outdated when our scientific knowledge increases. For example, books about intelligent, humanoid aliens on Mars are outdated now, because we now know such life doesn't exist on Mars. That doesn't mean the books are bad reads: Ray Bradbury's "The Martian Chronicles" and Robert Heinlein's "Stranger in a Strange Land" are both fine novels.
Also, some science fiction books become irrelevant when the technology described actually gets invented. This happened to many of Jules Verne's 19th-century novels (written before the term "science fiction" had been coined). His books depict things that were later invented for real, including skyscrapers, fax machines, and the Internet.
Fantasy books deal with magic and the supernatural--things which most of us don't believe are ever possible. Typically they take place in the past or in some quasi-historical setting with knights and castles and princesses, and they feature stuff from mythology and folklore, such as wizards, elves, fairies, and dragons.
But any story with supernatural elements can be called fantasy. That includes much of the horror genre: stories about vampires, werewolves, demons, and ghosts are all fantasy.
Many fantasy books actually take place in the present but feature traditional magical elements. The Harry Potter series is the most famous example, but many adult books, such as those by Charles de Lint, dabble in this too.
A fantasy book may even take place in the future. Terry Brooks' Shannara series takes place in the far future, after the earth experienced some kind of global disaster such as a nuclear holocaust and was returned to a primitive state, where magic instead of science came to rule.
Sometimes the line between science fiction and fantasy isn't easy to draw. As other answerers have noted, Star Wars features seemingly supernatural elements such as the Force and ghosts. But since the setting is overwhelmingly futuristic, it is usually classed as science fiction.
Actually, any story featuring psychic-type powers could be either fantasy or sci-fi depending on how it's presented. Orson Scott Card relates an experience when he submitted to a science fiction magazine a story about psychics on a distant planet. The editor rejected the story on the grounds that it was fantasy, not science fiction. Card was outraged at first, but then he realized he hadn't actually included in the story any information to alert the reader that it was set on a distant planet. The society he depicted was relatively primitive, so the editor assumed it was Earth in medieval times and interpreted the psychic powers of the characters simply as sorcery.
Thus, the line between science fiction and fantasy is usually based more on broad superficial themes (e.g. the presence of spaceships as opposed to fire-breathing dragons) than on actual plausibility.
Source(s):
Orson Scott Card, _How to Write Science Fiction and Fantasy_ (1990).
http://en.wikipedia.org/wiki/Jules_Verne…