Andy never sacrifices his belief in hope and redemption even while being immersed in the most difficult of situations. There are many moments when Andy certainly could feel that giving up hope would be appropriate. He is sentenced for a crime he didn't commit, serves a sentence that is not morally acceptable ("Only innocent man in Shawshank"), and finds his efforts to bring light to the darkened hole of Shawshank to be deferred at multiple moments. His desire to escape and not become an institutional man helps feed his pursuit of justice, of being happy in the world. In the final analysis, the fact that Andy never gives up his conception of hope allows him to pursue justice throughout his narrative.
Andy helped himself while achieving justice for the other inmates because as he was ingratiating himself to the guards and warden, he was secretly planning his escape. While he was offering to help the guards out with their taxes, he was secretly digging a huge hole in his cell. Because he became trusted more and more by the guards and the warden, no one thought to look behind the poster he had hanging in his cell.
Andy improved life in prison for the other prisoners. He helped get a library going at the prison. He helped the other prisoners study for their GED exams so that when they got out of prison, they would be more employable. He played operas over the loud speakers so the men could enjoy the music. Even though many of the things he did for the other inmates landed him "in the hole" (solitary), he did it anyway, endearing himself more and more to the other prisoners.
As he helped the warden launder his money, he secretly plotted how he would use the information in the future to eventually turn the warden in -- only after he, himself, had escaped to Mexico.
Andy was very crafty. He helped himself while pursuing justice for others.