I've been ruminating lately about the above-named Beatles song, perhaps in part because we're at a time and in a place where things do not seem working out for our country or the world, on many levels, but also due to its own extraordinary merits, beauty, and pathos - despite its surface optimism - as a song.
There's a longstanding genre of popular songs in which the character played by the singer conspicuously doesn't get it, adding irony and pathos to his or her romantic plight. To name two examples from songs covered by the Beatles, in "Please, Mr. Postman" we know perfectly well that it isn't the postman's fault no letters are arriving from the loved one. The singer is deflecting his (or in the Marvelettes' original version her) anxiety away from the real source of the problem.
Likewise, in "Slow Down," the woman who's "moving way too fast," and who needs to "gimme a little loving ... if you want our love to last," plainly doesn't want it to last. She's got a "boyfriend down the street," after all. So the singer is petitioning her in vain, and misdiagnosing the problem because it's less painful than admitting straight up that she has dumped him.
"We Can Work It Out" is a subtler, less overt version of this self-deceiving narrator motif. The song (mainly written by McCartney) opens mid-argument - we don't hear what the argument is actually about - with the singer insisting that his girlfriend see it "my way," not hers. "Do I have to keep on talking till I can't go on?"
This is not generally a good way of bridging disagreements: You don't say to the other person: "your way" is wrong, stop exasperating me. And for that matter, the singer openly admits that "my way" offers no guarantees. They will either "get it straight or say good night," and "only time will tell if I am right or I am wrong."
So you get the infectious optimism of the singer's insistence that "we can work it out" - conveyed also by the vocal performance, yet undercut by the realization that they probably won't work it out, that he is approaching it the wrong way - without adequate sympathy, flexibility, or understanding - and that he pretty much realizes where they're likely headed, even as this remains the best he can do to try to head it off.
One of the song's widely noted merits is the back-and-forth between McCartney's verses, which I've been quoting so far, and Lennon's terse middle-eight ("Life is very short and there's no time / For fussing and fighting my friend"). That section provides a great change of pace and musical contrast, but it's not really pessimism undercutting optimism, so much as weariness and impatience undercutting the pretense of optimism. And the slowdown at its end into 3/4 time as they head back to the verse ("So I will ask you once again ...") adds to the sense of impatience, impending failure, and just being stuck.
"We can work it out / We can work it out," the song ends - the singer radiating enthusiasm that is clearly just a thin shell masking anxiety - followed by a striking minor-key chord run on the harmonium that's held for a few seconds.