Welcome to the forum! I also tend to get ants and flies in my sap buckets, sure is gross, drives me crazy.
For ants, maybe try to use double sided tape below the tapand below the bucket. The tape might hold some of them back.
For flies, I have been using a wick in the taps, it allows the sap to drain into the buckets but keeps out other objects.
More recently, I began using a different method which I like a lot more...
Buy 5 gallon buckets from Tractor Supply, be sure to get the covers with them. buy the taps that go with the tubing as opposed to the traditional taps. Run the tubing from the tap and drill holes in the covers of the buckets just barely large enough to take the tubing. This tight seal will keep everything out of the buckets. I used this last year and was amazed how much nicer it was!