Those are most likely planaria. Don't worry, they don't bother anyone and aren't considered harmful. Sometimes fish eat them. Vaccuming the gravel may help get rid of some of them. Now the bugs are little tiny brown ones, right? I had those in my tank too. They don't harm anyone, my fish didn't mind their presence at all. They are rather unpleasant to look at though. Again, vaccuming the gravel helps. I doubt the planaria are related to the buggies.
Actually, over the summer I was away, and the fish were in my mom's care. She doesn't care for them that well, and the ammonia went up. First time ever that I've had so much ammonia. Anyway, the fish lived through the ammonia spike, but the buggies seem to have died off. Planaria too. Of course I don't reccomend you let your ammonia rise in order to kill them, but I just found it rather interesting.