
Formally means officially or in a way that follows an established custom. Formerly means previously or at an earlier time.
Ask whether you mean how or when
- Formally. The town formally reopened the building with a ribbon-cutting. The ceremony marked the official reopening.
- Formerly. The building formerly housed a bakery. The bakery was there in the past.
Both can appear in one sentence. The town formally reopened a building that formerly housed a bakery.
Try a shorter word in its place
Try officially or in a formal way for formally. In The guests dressed formally, the word describes their manner of dress. Try previously for formerly.
Both are adverbs. See Than vs. Then for another spelling choice where a word can tell you when something happened.