First, create your custom application and install it, then copy the templates from ERPNext / Frappe to your application.
eg:
erpnext/www/all-products/__init__.py -> your_app/www/all-products/__init__.py
erpnext/www/all-products/index.html -> your_app/www/all-products/index.html
erpnext/www/all-products/index.py -> your_app/www/all-products/index.py
...
Second, add template_apps in your application hook.py, it is the point,
eg:
template_apps = ['your_app', 'erpnext'] # apps order is important
After that, you can modify/overwrite the teamplates.