Basics:
To produce motoring action, it requires that a current-carrying conductor be present in a magnetic field.
To produce generating action, a conductor, a magnetic field, and relative motion between the two are required.
Explanation:
There are two voltages present in the DC motor which affect the amount of current through the armature and its direction: the terminal voltage applied (Vt) and the counterelectromotive force developed in the armature coil (CEMF).
In the normal case of motoring, no CEMF is initially present to oppose Vt and a large current flows through the low-resistance armature creating a magnetic field which interacts with the stator's magnetic field to produce motor action. This causes the armature to rotate since the requirements for motoring action are met. The direction of rotation can be determined by the right hand rule for motors, where the thumb points in the direction of conventional current flow, the index finger points in the direction of the magnetic field from north to south pole, and the direction of motion is given by the middle finger (provided all three fingers mentioned are at 90 degrees to each other).
Since the armature (a conductor) is now rotating in the stator's magnetic field, there is relative motion between the two, and the requirements for generator action are met. This is what produces the CEMF. The direction of the CEMF can be determined by the right hand rule for generators where the thumb points in the direction of relative motion, the index finger points in the direction of the magnetic field from north to south pole, and the direction of the positive pole of the CEMF is given by the middle finger (provided all three fingers mentioned are at 90 degrees to each other). The armature CEMF thus opposes the Vt, which is Lenz's Law, and limits the current flow during normal operation. The magnitude of the CEMF is determined by Faraday's Law, which states that the voltage generated is proportional to the rate at which the conductor cuts the magnetic lines of flux.
While motoring, Vt will always exceed CEMF at constant shaft load and speed. If the speed increases due to the load going down (as is the case when going down hill without any brakes applied), the rate at which the armature (conductor) cuts the magnetic lines of flux goes up, causing CEMF to go up. Now CEMF > Vt, producing a generating condition and current flows in the exact opposite direction that it was flowing while motoring, that is, back toward the positive pole of your battery (or other voltage source). As this occurs, the kinetic energy is converted into electrical and the DC machine speed slows.
I would think the energy of the generating current may be stored for later use, though I would not recommend recharging your battery with it directly, as problems may result due to the fact the current generated would be difficult to control and could overcharge your battery, producing gaseous hydrogen which may reach explosive levels. I would store the energy in a capacitor bank or moderate it somehow before charging the battery with it in a controlled fashion.
The dump trucks I drove in an iron mine during the summers while I attended college used this principle of converting the wheel motors into generators, called dynamic braking, to lower the speed of these huge trucks to a point where a friction brake could safely be applied without burning out the brake pads too frequently. The energy created by dynamic braking was radiated as heat through huge resistor banks rather than stored for reuse. You could see the grid packages glowing red at night sometimes on the trucks that had to go downhill carrying heavy loads frequently. I alway thought this was rather wasteful.
Best of luck with your understanding of this feature of electromagnetism.