It has been reported that the follower in a tandem configuration with no wall (0W) reduces the time-averaged input power by utilizing the vortex interception mode (Zhu et al., Phys. Rev. Lett., vol. 113, 2014, p. 238105). In the present study, a numerical simulation is conducted with two self-propelled flexible fins in the tandem configuration near a single wall (1W) and two parallel walls (2W). Contrary to the vortex interception for 0W, the follower employs spontaneously a mixed mode (i.e. a combination of the vortex interception mode and the slalom mode) for 1W and the slalom mode for 2W. Although the lateral motion of the follower for 0W, 1W and 2W is synchronized with the induced lateral flow generated by the leader, the time-averaged input power of the follower for 1W and 2W is reduced significantly due to the enhanced lateral flow by the vortex–vortex interaction near the wall. The jet-like flow opposite to the moving direction continuously hinders the movement of the follower for 0W, whereas the follower for 1W and 2W utilizes the negative horizontal flow when passing between the main vortex and the induced vortex near the wall, leading to a decrease of the thrust force acting on the follower allowing the follower to keep pace with the leader. The global efficiency of the schooling fins is optimized with a small heaving amplitude of the follower and a critical value of phase difference between the leader and follower when the values of the wall proximity and bending rigidity are moderate.