Generally, を is for direct objects and locations being passed through, and に is used for indirect objects and destinations and places where a state is taking place (that's kind of a weird way of saying that). However, there will be times when you just have to pay attention to which particle the verb takes, because some of them take one or the other.