Try turning your room lights on or opening your curtains 30minutes before you turn the tank lights on. Also if you have more than one light on the tank, then turn one on, wait an hour, then turn the other on.
At night before bed turn the room lights on, then turn the tank lights off. Wait 30minutes before turning the room lights off.
The fish are freaking out because they are going from a dark tank to a bright one and it is happening very quickly. It's like someone coming into your room during the night and shining a torch in your eyes. It isn't very pleasant for us and fish don't have eyelids so it is worse for them. You can also put some floating plants in the tank. This will reduce the amount of light getting thru to the fish as it will be filtered by the plants on the surface.
Poor water quality will also make fish nervous and panic all the time.