kymmie is right, go ahead and do another water change. A fully-cycled tank will have ammonia and nitrite readings of 0, with some level of nitrates (in general 40 ppm is getting to a dangerous level, ideally below 30 ppm, 20 or below is even better). Since you've got some nitrites in there, do a water change to dilute them down.
You must have done something recently that hurt or destroyed your bacteria population, since you mentioned the tank has been up and running for a couple of years. If the bacteria die off (or you put a bunch of fish in all at once, and the bacteria population is no longer large enough to support the bio-load), the tank will go through another cycle, meaning the ammonia will spike then the nitrites will spike until enough bacteria grow to consume them and keep them at a constant level of 0.
Now what happened to kill the bacteria, I don't know (or maybe you added a bunch of fish recently?). I imagine the medications you added wouldn't do that, but I suppose its a possibility. But, I bet that's why your fish are having a rough go of it, the tank is cycling right now, and the toxic ammonia and nitrites are claiming victims. Just watch the levels and do water changes as needed to keep the levels down, until they stay at 0 by themselves. Then following the advice of others in the thread, frequent and small water changes along with proper filter maintenance should prevent it from happening in the future! Keep us posted on the other test results if you like