Colin Kaepernick threw for 343 yards and three touchdowns, helping the San Francisco 49ers erase an early 14-point deficit and beat the St. Louis Rams 31-17 on Monday night.