Of course religion is legal in China. Chinese government has a department called State Administration of Religious Affairs to ensure freedom of religious belief. Due to large population of China, the number of followers of religions is large. There are 294 million followers of religions according to a survey of the Gallup Organization, most of whom are Buddhists.
Although China do have freedom of religious belief, what should be noted is that members of CCP(China Communist Party) are forbidden to become religious. Also, heresies and religons which endangers national security are banned.