Let us remember that Malvolio is at the heart of one of the central conflicts in the play. Twelfth Night was actually an important festival in Elizabethan times, that celebrated one last final raucous celebration of excess before the Christmas season was over and long, dark and difficult January began. In this play, the party spirit is represented by Sir Toby Belch, whose antics and desire to celebrated is matched by the dour and serious demeanour of Malvolio, who represents Puritan sacrifice in all of its black and white seriousness. Consider their confrontation in Act II scene 3, when Malvolio is awakened by the noise that Sir Toby and his cronies are making. Sir Toby delivers a very important line in this scene:
Dost thou think, because thou art virtuous, there shall be no more cakes and ale?
The supposed virtue of Malvolio is matched against the die-hard party spirit of Sir Toby, which of course leads to Maria's stratagem to make Malvolio look ridiculous.
This leads us to the second function of Malvolio. The way he is made to believe that his mistress is in love with him is one of the most hilarious elements of the play. Malvolio's self-love and his arrogance in showing himself so easily persuaded that Olivia is in love with him shows the dangers of ambition and of thinking ourselves to be more than we are.
Lastly, I would also argue that the character of Malvolio is important in the way that his presence strikes a discordant note in this otherwise light-hearted comedy. There is a sense in which Act IV scene 2, in which Feste plays with Malvolio as he is locked up, presents a punishment that is more than is deserved. Making Malvolio doubt his own sanity is pitiful and makes us feel sympathy for him, in spite of his many sins. Malvolio's final line in the final scene of the play, "I'll be revenged on the whole pack of you!", should make us question if this really is a comedy, and if it is, at what price the humour has been bought.