"Secrets of a Successful Marriage" is the twenty-second (and season finale) episode of Season 5.
Homer fears he may be a little slow, so he goes to the Adult Education Annex. While there, he plans to teach a class of his own on the secrets of a successful marriage, since that is the only thing he is good at and to keep them interested he is forced to his class Marge's secrets which she dislikes.
At Lenny's house, Homer and his buddies are playing poker. Homer ends up folding. Moe initially is overjoyed at winning the poker round, but then expresses irritation when he notices that Homer doesn't even realize he had a good hand (a straight flush, more specifically) before Carl tells Moe to calm down as there is no reason to get outraged at Homer, before admitting that Homer may be a little slow. Homer debates with himself and doesn't reply until after midnight that everyone else has left, with Lenny, who was downstairs at the time to get a snack, noticing Homer's presence, and notes that Homer really is slow. Homer debates himself again before being cut off by Lenny bluntly telling him to get out of his house. He plans to go to a class, but when he gets there, he sees Lenny and Moe teaching a class, he wants to teach one too. The adult learning center manager notices he is married and asks Homer to start a class called "Secrets of a Successful Marriage" where he explains how to live a perfect marriage, but he doesn't know what to say. Then he chooses to tell stories of Marge and his love life. When Marge finds out, she makes Homer promise he won't do it again.
However, his students by now are more interested in the secrets than learning anything so they threaten to leave, he tells more secrets and invites them to dinner to see what a successful marriage is like. Marge gets angrier and coldly throws them all out, including Homer. Homer can't come back in the house because she can't trust him anymore and he lives in the treehouse. He is so heartbroken, that he starts to go mad by making a fake Marge out of a plant and his clothes become worn and ripped. Meanwhile, Moe had heard that Marge broke up with Homer, the bartender moves in with her. When Homer seems ready to walk out of Marge's life for good he realizes something and tells her what he can give her that no one else can, complete and total dependence. Seeing this, Moe flees the scene. Marge doesn't believe that to be a good thing but Homer disagrees, they have been separated for only a day but he is already filthy, hungry and insane and that more than anything he can't afford to ever lose her trust because he clearly can't survive by himself. Marge eventually forgives him and he goes back home.
The next morning, Moe asks Marge through the kitchen window "if she is really happy". When he sees Homer, he screams and runs off.