I've noticed that some flies and bees don't always buzz when they fly so it can't be their wings making the buzzing sound or it would happen whenever they flew. Is the buzzing a form of communication, (wasps only seem to buzz when they're attacking something or defending themselves), and how do they make the sound?

The buzzing is definitely their wings, beating so rapidly that it sounds like a buzz. Different activities would require different motions for their wings, so the sound would change depending on what the insect is doing. For those times when you can't seem to hear it, it is possible that the sound is too high, or too quiet.

These sounds are sometimes used as communication. Some mosquitoes have courtship rituals based around matching wing beat harmonics with their prospective mates. Bumble bees vibrate the flower they are visiting to knock pollen around, using their flight muscles without actually beating their wings. Honey bees use their buzz in a similar way, but as part of their communication with other members of their hive about food sources (look for "waggle dance").