There are a number of factors which affect your entitlement to ESA whilst studying - most notable are whether the course is full-time or part-time, and whether your are in receipt of PIP in addition to ESA (or DLA).
If you are studying part-time, your entitlement to ESA is not usually affected. If you are studying full-time you normally cannot receive ESA unless either you receive PIP/DLA, or your ESA is contributions based.
Disability Rights have some useful FAQ on this https://www.disabilityrightsuk.org/how-we-can-help/individuals/education/frequently-asked-questions-students
Hope this helps!