Note: this is for standard STP/PVST not RSTP/PVRSTP
When the switch boots, if it is not connected to any other switches it will consider itself the root and all ports are Designated. Their state should now move to Forwarding (if they are up, connected to non-STP device). The switch moves the ports immediately into the Listening state for 15 seconds and then Learning state for 15 seconds, before moving to Forwarding. If when the switch boots it receives a superior BPDU and considers another switch root, the port may stay Blocking, or may transition to Forwarding (same process 15/15) if it is a Root port.
The switch always receives and processes BPDUs in any port state (apart from shutdown)
MaxAge (20 seconds) is mainly used when BPDUs stop arriving on an interface. It will wait MaxAge - MessageAge seconds before removing the current stored BPDU for the port and considering its own or other received BPDUs.
The root bridge election and port state are chosen on reception of every BPDU (or if priorities are changed within the bridge). They are not tied to any port state and happen continuously whenever there is a change that warrants a recalculation (BPDU arrives, STP settings changed, port state change)