Three millimeter molecular line observations of sagittarius B2. II. High-resolution studies of C18O, HNCO, NH2CHO, and HCOOCH3