The question of whether you need a license to sell candy can be answered simply as yes. Usually. You will probably need at least the business license that is required of any person residing in a city or county in the United States who wants to into business. Beyond that, each state has established certain guidelines in regards to selling food. For example, prepackaged candy would certainly receive less scrutiny than candy you made and packaged yourself. In the latter case, you will likely need additional permits and inspections.
The least restrictive way to get into candy selling would be to purchase candy from a wholesaler that has already been made and packaged. This relieves you of the responsibility of maintaining a kitchen or production facility that meets local health standards. If you're buying your candy to resell, the local city hall can tell you whether or not you'll need a business license to do so. Most jurisdictions don't want to miss out on sales tax and will regulate your endeavor.
Mobile events, such as local fairs, festivals, and these types of gathering could be quite profitable if you have a tasty product. Once again, while local rules might vary, you can expect that you will be required to obtain some sort of vendor permit, possibly including a health department inspection of your cart. For guidance, you could look to the city of Minneapolis, which requires people selling prepackaged food from their cars to have a what is called a limited mobile food vendor license.
If you decide to produce and package the candy yourself, expect to run into a host of other requirements, permits and licenses. Depending upon the scope of your operation, you might be required to meet the same equipment and health inspections standards that apply to restaurants and grocery stores. This would definitely apply if you plan to have a retail storefront where the public comes to you to buy. Selling a box of candy now and then, and only over the Internet, might have different regulations. Once again, check with your local city hall before proceeding.
A big factor to keep in mind if you plan to sell candy out of your house is that most residential neighborhoods are not commercially zoned, which means storefront types of businesses are restricted from being there. However, if you can show the powers-that-be that your endeavor will not create a nuisance to your neighbors with excessive traffic or odors, they might be amenable to issuing a zoning exception.