According to Islamic teachings, God rewards whoever behaves righteously in this life. As for the afterlife, Muslims believe that God knows the innermost secrets of human hearts and He will judge everyone with absolute justice.
The key issue to note is that a "good" act according to God is one that is done for his sake - not for personal desires, gain or other aims and purposes. Hence it is difficult to see how one can be good without following a code of conduct that is not done for God's sake.