How do the terms "fanboy" and "fangirl" differ from the generic term "fan?"
In my opinion it's mostly a difference in the degree of admiration and/or devotion:
A fan of a band might have most of their records and visit their concerts when they happen to be somewhere near him.
A fanboy has all of their records (including those bootleg records and a few unreleased ones) and goes to all of their concerts, even if they are on a different continent.
Actually "fanboy" might start earlier than that, but that's the basic idea.
Often the term fanboy also implies that the devotion to the topic of his fandom is blind and unreflected. A commonly used term is "Apple fanboy" for people who will praise all Apple products for being perfect and not listening when someone makes a reasonable argument that some little thing that came from Apple is less than perfect.
The implication here is that discussion with a "fanboy" about his topic has become impossible because he's beyond the realm of reason.
I don't know if "fan" was ever meant to indicate such a level of devotion.
Yes, "fanboy" (sometimes seen as "fanboi") is intended to be derogatory. The mere fact that the diminutive "boy" is attached to it should tell you that. The implication is that we are talking about someone who is not really a man. He probably still lives in his mom's basement, and whatnot.
There also is an implication in the word that the person in question will find a way to argue in support of the object of their fandom, no matter what the topic or situation.
"Fangirl" oddly isn't quite as derogatory. Partly, this is because "girl" isn't as derogatory as "boy". It could also have to do with the relative rarity of females in the realms of fandom. It could also have to do with the fact that we have other words (e.g., groupie) for the truly extreme female fans, so "fangirl" just gets the weaker leftovers.
I'd also like to note that (at least in the USA) "Fan" is typically used in a sports context, whereas "fanboy" is typically used for more geeky topics like Science Fiction. Both are now used outside their natural milieu, but as borrowings.
For example:
A crazy guy who paints himself blue and stands out in freezing weather with no shirt to watch his favorite football team play would be a fan.
A crazy guy who paints himself blue and stands out in freezing weather with no shirt to get tickets to see The Smurfs on opening day would be a fanboy.