CP - If you haven't seen this movie, you need to watch Gothic (1986) - it's a movie recounting the weekend Shelley gave birth to the idea of Frankenstein. It's pretty fantastical, but I really enjoyed the movie!
I'm guessing the costumes are from back when people dressed up to keep evil spirits at bay but I can't recall the candy
I've heard several theories about the costumes. One was that Halloween is the day when the ghouls come out and people dressed up like them so that the ghouls wouldn't bother them and think they were one of their own.
The villagers would dress in costume and parade through the streets at night with food, goodies etc and leave it some distance from the village. This was to lure the evil spirits away from the town and keep them happy somehere else.
The history of all hollows eve its actually quite facinating.