In each example, أَنْ and its imperfect form one Masdar Muawwal.
● أَمَرَنَا اللَّهُ أَنْ نَعْبُدَهُ — Allah commanded us to worship Him.
● أُمِرْتُ أَنْ أَعْبُدَ اللَّهَ — I was commanded to worship Allah.
● أَنْ تَذْبَحُوا بَقَرَةً — that you slaughter a cow; the second-group nūn is removed. (Al-Baqarah 2:67)
● عَسَى أَنْ تَكْرَهُوا شَيْئًا وَهُوَ خَيْرٌ لَكُمْ — perhaps you dislike something while it is good for you. (Al-Baqarah 2:216)
● In الْإِحْسَانُ أَنْ تَعْبُدَ اللَّهَ كَأَنَّكَ تَرَاهُ, the target construction is أَنْ تَعْبُدَ; كَأَنَّكَ contains a different particle.
The Masdar Muawwal is the whole أَنْ + فعل مضارع unit, not the particle alone.