Motor controllers are what convert the DC of your battery into 3 phase AC for your motor.
They determine the maximum current and hence wattage that goes to your motor and automatically adjust the amount of current sent depending on the throttle settings.
Some motor controllers are programmable and have adjustable current limits and other settings while others are fixed. Most e-bike controllers can be used with most motors, however pairing a high power controller with a low power motor will likely overheat the motor.
As its your motor controller that sets the maximum battery current, you must select a battery that can supply as many amps as your controller is rated for or more.
Controllers also act as switch mode power supplies and can trade off voltage for amps. This is why controllers will have a 'phase amp' and 'battery amp' setting. Battery amps determines your maximum battery current and hence max wattage (equivalent to horsepower) while phase amps is the maximum output current at slow speed and determines your maximum torque. Do note that its phase amps that cause heating in a motor (Watts dissipated as heat = Current ^ 2 * winding resistance), so while a high phase amp controller gives you more torque at slow speeds it will also cause much more heating when you use that extra torque.
Controllers come with a few different features that should be looked for:
Current or Speed throttle mode: Current mode is much preferred as it allows you to adjust the output torque of the motor for a smooth comfortable and efficient ride. Speed mode is much like the throttle on a tractor, it uses full power to reach a desired speed and then maintains that speed, causing sudden jolts of power whenever you adjust the throttle. Sadly speed throttle mode is much more common then current throttle mode for budget controllers.
Programmability: Some controllers can be programmed via bluetooth or via a cable to a PC or laptop, while others are just fixed. Programmable controllers are much more flexible offering a range of settings like battery amp limit, phase amp limit, soft start, adjustable speed limits, adjustable soft start, etc.
Sine wave or square/trapezoidal: Sine wave drives are slightly more efficient and cause the motor to produce much less noise then square wave.