Insert data through linked server into two remote related tables
You have to use sp_executesql or openquery ..

E.g. pseudo code .. 

declare @remoteIdentity (ID int)
insert into @remoteIdentity 
EXEC LNK_AAA_2_BBB.master..sp_executesql N 'select * from #server_AAA_table_1
select SCOPE_IDENTITY() AS ID';
SELECT * FROM @remoteIdentity;


Read up : Best way to get identity of inserted row?