How long are text messages saved in the iCloud server?
As of the last update of Apple's iOS Security Guide, May 2016:


  iMessage messages are queued for delivery to offline devices. Messages are currently stored for up to 30 days.


(emphasis mine)

Note this time period has increased from a prior version of this guide, which stated that messages were queued for up to seven days.

If, by "text message", you actually mean SMS messages, those do not cross onto Apple's servers at all unless you have SMS Forwarding enabled, to have messages from your iPhone forwarded to other devices such as a Mac or iPad. Forwarded SMS messages are encrypted in the same method as iMessage messages (elaborated in the guide). It appears that the 30-day timeframe also applies to forwarded SMS messages.