My iPhone messages changes colors at times between green and blue or other way around. How do I stop this
If your iPhone cannot send the message as an iMessage (blue) it will fallback to SMS/MMS (green). This can happen for a bunch of reasons, which I've listed below. 


Network is unavailable: iMessage uses internet access however SMS is able to work over raw cell network. This is very helpful if you're on the edge of a service area or are roaming. To fix this issue make sure you have proper network access.  
iMessage services could not be reached: if you have functional internet access iMessage may still fall back to SMS if for whatever reason the iMessage service is blocked on the network or there is a problem on Apple's end
The user is no longer available on iMessage: If a user used to be registered with iMessage (and you successfully sent messages to them this way in the past) your iPhone will automatically try first to send through iMessage without first checking if that number/address still has iMessage activated on it. The number may suddenly disappear from iMessage if for example the user gets an Android phone. This should really only happen once. 


This is nothing to worry about, nothing weird is going on. 

Note that this is all about falling back from iMessage to SMS. I have never seen it go from SMS to iMessage (green to blue) however. I do not believe iOS ever decides to try sending as iMessage if SMS fails. iOS will however check sometimes when you send SMS if the recipient suddenly is registered with iMessage so that can be used in the future.