Think of how this poem would sound if "lonely" were omitted. If you can describe a cloud as "lonely," then you could describe it as almost anything: happy, tired, bored, aimless, hopeful. Think about "I wandered hopeful as a cloud." Does that make any less sense? Well, in the context of the poem yes, but by itself, maybe not. "Lonely" seems to be necessary to make the contrast with the happiness of the daffodils.
Fluttering and dancing in the breeze. (line 6)
The daffodils are first introduced as "dancing" at the end of the first stanza. There is no reason at this point to think that the dancing is especially happy. It could just be your run-of-the-mill metaphor to produce a run-of-the-mill nature description. The description of the daffodils starts out naturalistic and becomes tinged with more and more emotion as the poem goes on.
The waves beside them danced; but they Out-did the sparkling waves in glee: (lines 13-14)
The fact that the daffodils are happier than the waves suggests that their so-called "happiness" is dependent on the speaker’s perception of them. For example, he probably doesn’t think the waves are as happy because he associates them with the wind and the brewing storm. Waves can make people feel uneasy. But stationary flowers: who’s afraid of a little flower?
A poet could not but be gay, In such a jocund company: (lines 15-16)
Glee? Gay? Jocund? It’s as if he’s running out of words for "happy." The point is that the joy of the daffodils is irrepressible and contagious.
Which is the bliss of solitude; And then my heart with pleasure fills, And dances with the daffodils. (22-24)
No, wait, we were wrong. He has more synonyms for "happiness" in his bag of tricks: now it’s "bliss" and "pleasure". Notice that "solitude" is exactly what made him unhappy, or "lonely," at the beginning of the poem. Or maybe "lonely" just meant "alone," and we were not supposed to give it such a negative connotation.