Rather than choosing separate shirts and pants, you should be wearing a suit. The most important thing to remember about styling your suit is that it should fit correctly.
This means the jacket arm should stop at your wrist, the pant legs right above your heel, and the collar shouldn't be too tight. Make sure that when your suit is buttoned, it doesn't bunch around your waist.
If your office is formal but not too staunchly, you can mix and match the colors of your jacket and pants. In more formal offices, you should opt for a single-breast suit.
If you want to go full formal, choose a three-piece suit.
Suits should be worn with button-ups rather than button-downs. You can experiment with patterns, but only on the shirt or the jacket - never both. Stick to colors that go well together.
For a formal look, you should be wearing a tie.
Never mix patterns. You can choose a patterned tie or suit, but not both.