Since wandwork is not absolutely necessary to cast spells, is it possible for a wizard to accidentally cast spells while asleep, akin to sleepwalking or nocturnal emission?
Harry Potter once grew his hair back overnight after Aunt Petunia cut it off, while asleep:
Next morning, however, he had gotten up to find his hair exactly as it had been before Aunt Petunia had sheared it off.
Harry Potter and the Sorcerer's Stone, chapter 2
After the clarification of what the OP meant by spell, I'd say that it's possible, but probably not very likely. You would have to make the appropriate motion, and think/sleeptalk the right words, at the same time. It presumably is possible, though.
It might be possible because it's stated in the book series that just simply saying a spell in your mind can properly cast it. I found this quote in the Why does pronunciation of spells matter? question somebody commented earlier and found this quote within one of the answers:
"Pointing his wand at nothing in particular, he gave it an upward flick and said Levicorpus! inside his head. "Aaaaaaaargh!" There was a flash of light and the room was full of voices: Everyone had woken up as Ron had let out a yell. Harry sent Advanced Potion-Making flying in panic; Ron was dangling upside down in midair as though an invisible hook had hoisted him up by the ankle."
Now if the wizard was sleeping walking and had used the same motion and thought process I would think that it would allow the spell to work like normal. It's also possible to use wandless magic as well, so it might be possible to do some forms of magic while asleep.