When the master printer was building a page and discovered that a particular sort was empty, he would get angry. Thus the term "out of sorts".
Similarly, the exclamation point came from the Latin word "Lo", meaning something important that should be heeded. (Lo and behold...)