matrix won't accelerate. on 2006 Toyota Matrix

sometimes my matrix will start up fine and then check engine lite is on car starts to idle and gas pedal is pushed and nothing. i turn off car it idles alittle but no acceleration then i turn it off again and car accelerates fine then engine lite goes off. a couple of days go by and again the same thing.

Asked by for the 2006 Toyota Matrix