The imperfetto is used to express either habits, actions that lasted a long time in the past or actions that are repeated in the past. It is usually followed or preceded by expressions that indicate that the action was a habit, such as 'everyday', 'always', 'every time', 'on every Sunday afternoon'.
On the contrary, the passato prossimo expresses actions that only took place once or that didn't last long in the past. It is often followed or preceded by expressions which show that the action only happened on a special occasion, such as 'once', 'that time', 'that day'.