There isn't exactly a 'purpose' to any life form. But I think I know what you are getting at.
Ants play differing roles throughout the world. There are many different species of ant, over 20,000, in fact. Some certainly do play a role in pollination, while others help to keep other insect populations in check.
As for flies, again there are many different species, some, like the ants, play a role in pollination, while others are predators. The maggots (larvae) of some flies feed on fruits and nuts, while others play a significant role in the breakdown of dead animal tissue. Some maggots are even used in medical treatments to clean infected wounds of dead and decaying tissue.
Now for those pesky mosquitoes. What a pain they are. But it is only the female which will give you those irritating bites. They need blood for egg production. Mosquitoes, and some flies, can be a serious health risk. Some mosquitoes can carry malaria, yellow fever and dengue fever, some flies can carry sleeping sickness. But even the dreaded mosquito has its advantages; their larvae help to keep algae and bacteria in check in water.
Then you must consider that all three, in both their larvae and adult stage, provide food for birds, reptiles, amphibians, fish and other animals. Even man is known to eat some, such as Honeypot ants.