I am going over the cases when に and で are used with location. According to the "Dictionary of Basic Japanese Grammar", に is used when something exists in a specific location (page 299) and で is used for events taking place at specific locations (page 105.)
The difference is rather clear, however there are two exceptions: 住む and 勤める. While I can understand that 住む might mean "to exist", the meaning of 勤める is less clear (I exist working at the office?). Are there other examples/exceptions to this?
に is used when what the predicate means involves the location and will not make sense without it. Examples are: when someone/something is located somewhere (いる, ある), lives somewhere (住む), goes somewhere (行く), commutes to somewhere (通勤する, 通学する, 勤める, 通う), etc., the very meaning expressed by the predicate necessarily involves the notion of place.
で is used when the location is not necessary to express the meaning of the predicate. For example, reading, running, studying, etc. do not require the notion of location to express their meaning. Of course, the agent needs to be at some location in order to do these things, but that just follows from our encyclopedic knowledge about the world, and is irrelevant to the description of the meaning of these predicates.