Edit in JSFiddle

    function animar_inicio() {
                document.getElementById('quadrado').setAttribute("style","-moz-transition-property: -moz-transform, -moz-transform-origin; -moz-transition-duration:2s;-moz-transform:rotate(-45deg);");
                setTimeout(function () { animar_fim() }, 2000);  
        }

    function animar_fim() { 
                document.getElementById('quadrado').setAttribute("style","-moz-transition-property: -moz-transform, -moz-transform-origin; -moz-transition-duration:2s;-moz-transform:rotate(0);");
                setTimeout(function () { animar_inicio() }, 2000);  
    } 
                           

 animar_inicio();
                           
<html>
    <body>
        <div id='quadrado'>Quadrado</div>
    </body>
</html>