You mentioned having a 3 way switch for the pantry. Is there actually a second switch somewhere that is also supposed to control the pantry light, or did someone just throw in a 3 way switch in a situation where a normal, single pole switch would have worked? How many screws are present on the switch that controls your fan and fan light, not counting the green grounding screw?
Where does the power enter this circuit? It could enter the box with the double light switch, the box for the pantry light switch, the box the fan is mounted on, or the box that the pantry light is mounted on.
Helping you rewire this mess to work properly is going to require detailed information about exactly what wires are present in each location. There are several "right" ways to do the wiring in this situation, and picking the RIGHT "right" way for you will depend upon what wires are already present.
I'm going to go out on a limb with one possible answer to your question. Just keep in mind that it's only a guess since I don't have all of the information needed to know for sure.
You know how a duplex receptacle has 2 sets of connections on it, and you can run power in to the top two screws and out through the bottom two screws and on to the next outlet, right? Well, it may be possible that some very inexperienced person in the past saw a 3 or 4 way light switch and thought they could do the same thing. If they tried to daisy chain the power between light switches the way you would do it between receptacles, and they chose just the right (or, in this case, WRONG) way to attempt it, it could lead to your current situation.
In any case, the situation needs to be fixed sooner rather than later. The fact that your lights are functioning this way indicates that whoever did the electrical work had absolutely no idea what he was doing, and he VERY likely created unsafe conditions in your home. If you aren't up to making a diagram of the current wiring configuration for us to look at here, then you really, really need to get an electrician in to sort out your problems before your house burns down or someone gets electrocuted.
Open up the switch box, and have a look how it's wired. Without more information (photos, diagrams, etc.), the following information is an educated guess.
One of the colored lines (red, black) is likely always hot, while the other is controlled by the switch. The white is most probably neutral, and the bare/green is almost certainly ground.
If this is the case, then connecting the devices is simple.
- Connect all the grounding conductors together.
- Connect the incoming white wire to the white wire going to the receptacle, and to the white wire for the light.
- Connect the always hot colored wire to the hot wire leading to the receptacle.
- Connect the switched hot colored wire to the hot wire for the light.
Again, this is a guess based on the limited information you've provided.
Best Answer
Updated solution per comment:
The fire alarm should not be connected to a switch at all. It's likely that it is connected to the same switch as the light but with the wires reversed. The solution would be to remove the fire alarm black & white wires from the switch and splice them in the box to the cable that feeds the switch, but before it "hits" the switch.
Old answer saved for posterity... i.e. it may help someone else:
There's so many ways to get into this situation and it's impossible to guess which one you're in but: Take a look at this site: https://www.homeimprovementweb.com/information/how-to/three-way-switch.htm It contains diagrams for all the different ways of wiring a light with two switches. Something you will notice about the diagrams is that there is no other load (device that consumes electricity) in the diagram.
In your situation a separate load, the fire alarm, was introduced into the two-switch system and it should not be. In each diagram you will see a section that says something like
From power source
. This is where the electricity is coming in and this is where your fire alarm should be spliced in. i.e. The fire alarm should be connecting to the power supply before the two-switch system.Now, how to fix this? If you're lucky the electrical box that feeds the fire alarm will have two separate three-wire cables running through it and it just happens to be spliced into the wrong one. In this case you just need to re-splice. But it's also possible that there is no 2nd wire in which case you will need to splice into whichever light-switch box (or possibly the fan box) and run a three-wire cable to your fire alarm. Yes, this could be just as painful as it sounds. If you have drywall up you may need to get into the wall to thread the cable between the boxes and then have to repair and paint...
In any case, good luck.
P.S. It's also possible that the power supply is coming into this system from the fan's electrical box. If this is the case then your worst case (having to bust through the drywall) becomes a little easier.
Here's a sample diagram (modified from option #1 of the web site given above) of where a separate cable may be spliced in so it doesn't behave the way you're describing.