What could be wrong if a 2001 Alero idles between 300-1000 rpms in park and neutral but in gear idles and runs fine?

Most likely its not your mass air flow sensor its gonna be your tp sensor (throttle position) or your down stream oxygen sensor because a MAF sensor controls your ITS or Ideal temp sensor witch can affect your accel and your idle when under a load but when its at rest or idle it will be affected by a tp sensor of O2 sensor they call the O2 sensor the spark plug that never gets changed..