[Lowest probability] First eliminate software-related issues: How long has this been occurring? Was there at any point the usb connections were working flawlessly? Any recent software install that may conflict with keyboard and mouse drivers?
[Most probable] If this is frontal usb of the case, check the usb header connections on the motherboard and make sure the connection is tight. They should be labelled. Most of the motherboards I encountered have them on the bottom-right corner. This is from the viewpoint of opening the left side panel of the case.
Last result, use a different keyboard or mouse and try to reproduce the problem. Likewise, take your original keyboard and mouse and try it on a different system. This test will determine if the problems likes with your original peripheral devices or your motherboard.
If you determine the usb port is indeed damaged, and you don't want to replace the motherboard (I sure wouldn't), you could always install USB pci card.