上手 and 下手 are words that objectively refer to someone's skill. 得意 and 苦手 are, as the kanji suggest, more or less related to someone's feeling. 得意 has a connotation of having confidence in one's skill, and 苦手 has a connotation of disliking or lacking confidence.
彼は料理が下手です means he is not a skillful cook, but depending on the context, he may like cooking. There is an idiom 下手の横好き. On the other hand, 彼は料理が苦手です means he is not confident in his ability to cook, or he simply dislikes cooking. Still, in typical situations, these two are interchangeable.
上手に書けた文章 is a well-written sentence. 得意に書けた文章 makes no sense.
私は彼のことが苦手です usually means the speaker does not like the way he talks or his personality. See the definitions of 苦手意識, too. 私は彼のことが下手です doesn't make sense because "he" is not a skill. Likewise you can say 寿司は苦手です but not 寿司は下手です.
Those words can be used both in informal and formal situations. Publicly saying 下手 referring to someone else's skill can sound too direct and impolite, but saying テニスが下手 referring to the speaker themselves is fine regardless of the formality.